Skip to content

Commit 3951757

Browse files
authored
Fixed string escaping omissions (#599)
I received a `RegexpError` when I typed `::Array[`. ::Array[/Users/mi/ghq/github.com/ruby/irb/lib/irb/completion.rb:236:in `retrieve_completion_data': premature end of char-class: /^Array[/ (RegexpError)
1 parent c2e7002 commit 3951757

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

lib/irb/completion.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace
233233
if doc_namespace
234234
candidates.find { |i| i == receiver }
235235
else
236-
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
236+
candidates.grep(/^#{Regexp.quote(receiver)}/).collect{|e| "::" + e}
237237
end
238238

239239
when /^([A-Z].*)::([^:.]*)$/

test/irb/test_completion.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def test_complete_absolute_constants_with_special_characters
310310
assert_empty(IRB::InputCompletor.retrieve_completion_data("::A.", bind: binding))
311311
assert_empty(IRB::InputCompletor.retrieve_completion_data("::A(", bind: binding))
312312
assert_empty(IRB::InputCompletor.retrieve_completion_data("::A)", bind: binding))
313+
assert_empty(IRB::InputCompletor.retrieve_completion_data("::A[", bind: binding))
313314
end
314315

315316
def test_complete_reserved_words

0 commit comments

Comments
 (0)