aboutsummaryrefslogtreecommitdiffstats
path: root/lib/reline/line_editor.rb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-03-24 14:25:06 +0900
committeraycabta <aycabta@gmail.com>2021-03-24 15:43:34 +0900
commit89caf51d9346343156d5b9f1659131414c055ebd (patch)
tree76b14d832e530b5cea65a521e016425deebcd53e /lib/reline/line_editor.rb
parent758f2b35f93478c481902d9d3f8876216a5dcc4d (diff)
downloadruby-89caf51d9346343156d5b9f1659131414c055ebd.tar.gz
[ruby/reline] Suppress crashing when completer_{quote,word_break}_characters is empty
https://github.com/ruby/reline/commit/c6f1164942
Diffstat (limited to 'lib/reline/line_editor.rb')
-rw-r--r--lib/reline/line_editor.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 4e5860ceb9..5a2a3f115f 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -1224,8 +1224,16 @@ class Reline::LineEditor
end
def retrieve_completion_block(set_completion_quote_character = false)
- word_break_regexp = /\A[#{Regexp.escape(Reline.completer_word_break_characters)}]/
- quote_characters_regexp = /\A[#{Regexp.escape(Reline.completer_quote_characters)}]/
+ if Reline.completer_word_break_characters.empty?
+ word_break_regexp = nil
+ else
+ word_break_regexp = /\A[#{Regexp.escape(Reline.completer_word_break_characters)}]/
+ end
+ if Reline.completer_quote_characters.empty?
+ quote_characters_regexp = nil
+ else
+ quote_characters_regexp = /\A[#{Regexp.escape(Reline.completer_quote_characters)}]/
+ end
before = @line.byteslice(0, @byte_pointer)
rest = nil
break_pointer = nil
@@ -1246,14 +1254,14 @@ class Reline::LineEditor
elsif quote and slice.start_with?(escaped_quote)
# skip
i += 2
- elsif slice =~ quote_characters_regexp # find new "
+ elsif quote_characters_regexp and slice =~ quote_characters_regexp # find new "
rest = $'
quote = $&
closing_quote = /(?!\\)#{Regexp.escape(quote)}/
escaped_quote = /\\#{Regexp.escape(quote)}/
i += 1
break_pointer = i - 1
- elsif not quote and slice =~ word_break_regexp
+ elsif word_break_regexp and not quote and slice =~ word_break_regexp
rest = $'
i += 1
before = @line.byteslice(i, @byte_pointer - i)