From 6ce15fce1cf92bd2d86d04ceccd501a383656b81 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Mon, 2 Oct 2023 13:13:24 +0200 Subject: [PATCH] Fix string index error in tab completion code, fixes #51540 (#51541) --- stdlib/REPL/src/REPLCompletions.jl | 2 +- stdlib/REPL/test/replcompletions.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index 59fcd29e4f7f3..fad8af86b125d 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -975,7 +975,7 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff append!(suggestions, complete_keyval(name)) end if dotpos > 1 && string[dotpos] == '.' - s = string[1:dotpos-1] + s = string[1:prevind(string, dotpos)] # First see if the whole string up to `pos` is a valid expression. If so, use it. ex = Meta.parse(s, raise=false, depwarn=false) if isexpr(ex, :incomplete) diff --git a/stdlib/REPL/test/replcompletions.jl b/stdlib/REPL/test/replcompletions.jl index 58b29fccc66a6..a113d85a66977 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -23,6 +23,8 @@ let ex = quote end type_test = Test_x(Test_y(1)) (::Test_y)() = "", "" + unicode_αβγ = Test_y(1) + module CompletionFoo2 end @@ -253,6 +255,11 @@ let s = "Main.CompletionFoo.type_test.x" @test s[r] == "x" end +let s = "Main.CompletionFoo.unicode_αβγ.y" + c, r = test_complete(s) + @test "yy" in c +end + let s = "Main.CompletionFoo.bar.no_val_available" c, r = test_complete(s) @test length(c)==0