ruby-changes:65642
From: aycabta <ko1@a...>
Date: Wed, 24 Mar 2021 15:43:54 +0900 (JST)
Subject: [ruby-changes:65642] 89caf51d93 (master): [ruby/reline] Suppress crashing when completer_{quote, word_break}_characters is empty
https://git.ruby-lang.org/ruby.git/commit/?id=89caf51d93 From 89caf51d9346343156d5b9f1659131414c055ebd Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Wed, 24 Mar 2021 14:25:06 +0900 Subject: [ruby/reline] Suppress crashing when completer_{quote,word_break}_characters is empty https://github.com/ruby/reline/commit/c6f1164942 --- lib/reline/line_editor.rb | 16 ++++++++++++---- test/reline/test_reline.rb | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 4e5860c..5a2a3f1 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1224,8 +1224,16 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1224 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 https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1254 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) diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb index d2de469..0f32ec4 100644 --- a/test/reline/test_reline.rb +++ b/test/reline/test_reline.rb @@ -65,6 +65,8 @@ class Reline::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L65 Reline.completer_word_break_characters = "[".encode(Encoding::ASCII) assert_equal("[", Reline.completer_word_break_characters) assert_equal(get_reline_encoding, Reline.completer_word_break_characters.encoding) + + assert_nothing_raised { Reline.completer_word_break_characters = '' } ensure Reline.completer_word_break_characters = completer_word_break_characters end @@ -89,6 +91,8 @@ class Reline::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L91 Reline.completer_quote_characters = "`".encode(Encoding::ASCII) assert_equal("`", Reline.completer_quote_characters) assert_equal(get_reline_encoding, Reline.completer_quote_characters.encoding) + + assert_nothing_raised { Reline.completer_quote_characters = '' } ensure Reline.completer_quote_characters = completer_quote_characters end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/