From 8b70d7be3222bf802c3ee688efd321da5c4fa3c5 Mon Sep 17 00:00:00 2001 From: Simeon David Schaub Date: Tue, 30 Jul 2024 20:56:28 +0200 Subject: [PATCH] `strip_gensym`: handle unicode correctly fixes JuliaDebug/Cthulhu.jl#583 --- src/utils.jl | 4 ++-- test/runtests.jl | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 65e6210..6927e54 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -201,10 +201,10 @@ function strip_gensym(str::AbstractString) if startswith(str, '#') idx = findnext('#', str, 2) if idx !== nothing - return Symbol(str[2:idx-1]) + return Symbol(str[2:prevind(str, idx)]) end end - endswith(str, "##kw") && return Symbol(str[1:end-4]) + endswith(str, "##kw") && return Symbol(str[1:prevind(str, end-3)]) return Symbol(str) end diff --git a/test/runtests.jl b/test/runtests.jl index 72d6913..d4ae8b8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -432,3 +432,8 @@ end body, _ = CodeTracking.definition(String, which(diffminmax, (Any,))) @test body == "diffminmax((min, max)) = max - min" end + +@testset "strip_gensym with unicode" begin + @test CodeTracking.strip_gensym("#𝓔′#90") == :𝓔′ + @test CodeTracking.strip_gensym("𝓔′##kw") == :𝓔′ +end