Skip to content

Commit

Permalink
fix Dict completion when using non-ASCII (fix JuliaLang#23004)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Jul 29, 2017
1 parent 85a2555 commit da1e1b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/repl/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,18 @@ function dict_identifier_key(str,tag)
str_close = str
end

frange, end_of_indentifier = find_start_brace(str_close, c_start='[', c_end=']')
frange, end_of_identifier = find_start_brace(str_close, c_start='[', c_end=']')
isempty(frange) && return (nothing, nothing, nothing)
obj = Main
for name in split(str[frange[1]:end_of_indentifier], '.')
for name in split(str[frange[1]:end_of_identifier], '.')
Base.isidentifier(name) || return (nothing, nothing, nothing)
sym = Symbol(name)
isdefined(obj, sym) || return (nothing, nothing, nothing)
obj = getfield(obj, sym)
# Avoid `isdefined(::Array, ::Symbol)`
isa(obj, Array) && return (nothing, nothing, nothing)
end
begin_of_key = findnext(x->!in(x,whitespace_chars), str, end_of_indentifier+2)
begin_of_key = first(search(str, r"\S", nextind(str, end_of_identifier) + 1)) # 1 for [
begin_of_key==0 && return (true, nothing, nothing)
partial_key = str[begin_of_key:end]
(isa(obj, Associative) && length(obj) < 1e6) || return (true, nothing, nothing)
Expand Down Expand Up @@ -547,7 +547,7 @@ function completions(string, pos)
elseif c==']'
c_start='['; c_end=']'
end
frange, end_of_indentifier = find_start_brace(string[1:prevind(string, i)], c_start=c_start, c_end=c_end)
frange, end_of_identifier = find_start_brace(string[1:prevind(string, i)], c_start=c_start, c_end=c_end)
startpos = start(frange)
i = prevind(string, startpos)
elseif c in ["\'\"\`"...]
Expand Down
4 changes: 4 additions & 0 deletions test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ ex = quote
end
test_repl_comp_dict = CompletionFoo.test_dict
test_repl_comp_customdict = CompletionFoo.test_customdict
test_dict_ℂ = Dict(1=>2)
end
ex.head = :toplevel
eval(Main, ex)
Expand Down Expand Up @@ -748,3 +749,6 @@ test_dict_completion("CompletionFoo.test_dict")
test_dict_completion("CompletionFoo.test_customdict")
test_dict_completion("test_repl_comp_dict")
test_dict_completion("test_repl_comp_customdict")

# Issue #23004: this should not throw:
@test REPLCompletions.dict_identifier_key("test_dict_ℂ[\\", :other) isa Tuple

0 comments on commit da1e1b6

Please sign in to comment.