summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGo <[email protected]>2024-05-26 17:28:21 +0900
committergit <[email protected]>2024-05-26 08:28:25 +0000
commit508f3310481c34fe146bcd6775041847d40520c9 (patch)
tree7cbabc8beeb0eef0d052a2239cdf897a81583a4d
parentd2c4363e0c41c1512eb100981134db210c092126 (diff)
[ruby/reline] allow space in config value
(https://github.com/ruby/reline/pull/705) * allow space in config value fix https://github.com/ruby/reline/pull/657 * remove inline comments * Revert "remove inline comments" This reverts commit https://github.com/ruby/reline/commit/2438347c1a10. * refactoring * remove unnecessary comment handling https://github.com/ruby/reline/commit/d60f1e1e39
-rw-r--r--lib/reline/config.rb17
-rw-r--r--test/reline/test_config.rb12
2 files changed, 20 insertions, 9 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index d44c2675ab..62c6d105b3 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -182,9 +182,10 @@ class Reline::Config
next if if_stack.any? { |_no, skip| skip }
case line
- when /^set +([^ ]+) +([^ ]+)/i
- var, value = $1.downcase, $2
- bind_variable(var, value)
+ when /^set +([^ ]+) +(.+)/i
+ # value ignores everything after a space, raw_value does not.
+ var, value, raw_value = $1.downcase, $2.partition(' ').first, $2
+ bind_variable(var, value, raw_value)
next
when /\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/o
key, func_name = $1, $2
@@ -234,7 +235,7 @@ class Reline::Config
end
end
- def bind_variable(name, value)
+ def bind_variable(name, value, raw_value)
case name
when 'history-size'
begin
@@ -259,7 +260,7 @@ class Reline::Config
when 'completion-query-items'
@completion_query_items = value.to_i
when 'isearch-terminators'
- @isearch_terminators = retrieve_string(value)
+ @isearch_terminators = retrieve_string(raw_value)
when 'editing-mode'
case value
when 'emacs'
@@ -301,11 +302,11 @@ class Reline::Config
@show_mode_in_prompt = false
end
when 'vi-cmd-mode-string'
- @vi_cmd_mode_string = retrieve_string(value)
+ @vi_cmd_mode_string = retrieve_string(raw_value)
when 'vi-ins-mode-string'
- @vi_ins_mode_string = retrieve_string(value)
+ @vi_ins_mode_string = retrieve_string(raw_value)
when 'emacs-mode-string'
- @emacs_mode_string = retrieve_string(value)
+ @emacs_mode_string = retrieve_string(raw_value)
when *VARIABLE_NAMES then
variable_name = :"@#{name.tr(?-, ?_)}"
instance_variable_set(variable_name, value.nil? || value == '1' || value == 'on')
diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb
index 6068292847..03e4178f32 100644
--- a/test/reline/test_config.rb
+++ b/test/reline/test_config.rb
@@ -459,6 +459,17 @@ class Reline::Config::Test < Reline::TestCase
ENV['INPUTRC'] = inputrc_backup
end
+ def test_inputrc_raw_value
+ @config.read_lines(<<~'LINES'.lines)
+ set editing-mode vi ignored-string
+ set vi-ins-mode-string aaa aaa
+ set vi-cmd-mode-string bbb ccc # comment
+ LINES
+ assert_equal :vi_insert, @config.instance_variable_get(:@editing_mode_label)
+ assert_equal 'aaa aaa', @config.vi_ins_mode_string
+ assert_equal 'bbb ccc # comment', @config.vi_cmd_mode_string
+ end
+
def test_inputrc_with_utf8
# This file is encoded by UTF-8 so this heredoc string is also UTF-8.
@config.read_lines(<<~'LINES'.lines)
@@ -542,4 +553,3 @@ class Reline::Config::Test < Reline::TestCase
ENV['HOME'] = home_backup
end
end
-