From a049dfd10a3b9ae24a1822e807398422e87d142f Mon Sep 17 00:00:00 2001 From: Mark Delk Date: Tue, 13 Apr 2021 21:23:07 -0500 Subject: [PATCH] [ruby/reline] ensure reline's encoding is used when reading inputrc character values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change ensures we use `Reline::IOGate`'s `encoding` when converting characters from their integer values. This fixes an issue that may occur if you have UTF characters in your `.inputrc`, but your default encoding isn't set. For example: ``` > 127864.ord.chr RangeError: 127864 out of char range from (pry):1:in `chr' > Reline::IOGate.encoding => # > 127864.ord.chr(Reline::IOGate.encoding) => "🍸" ``` https://github.com/ruby/reline/commit/cf372fc0fc --- lib/reline/config.rb | 7 ++----- test/reline/test_config.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/reline/config.rb b/lib/reline/config.rb index 9689c8f51d..dd81a23ea7 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -292,11 +292,8 @@ class Reline::Config end def retrieve_string(str) - if str =~ /\A"(.*)"\z/ - parse_keyseq($1).map(&:chr).join - else - parse_keyseq(str).map(&:chr).join - end + str = $1 if str =~ /\A"(.*)"\z/ + parse_keyseq(str).map { |c| c.chr(Reline::IOGate.encoding) }.join end def bind_key(key, func_name) diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb index 2cca0e71f7..2ada00c154 100644 --- a/test/reline/test_config.rb +++ b/test/reline/test_config.rb @@ -286,6 +286,16 @@ class Reline::Config::Test < Reline::TestCase ENV['INPUTRC'] = inputrc_backup end + def test_inputrc_with_utf + @config.read_lines(<<~'LINES'.lines) + set editing-mode vi + set vi-cmd-mode-string 🍸 + set vi-ins-mode-string 🍶 + LINES + assert_equal @config.vi_cmd_mode_string, "🍸" + assert_equal @config.vi_ins_mode_string, "🍶" + end + def test_xdg_config_home home_backup = ENV['HOME'] xdg_config_home_backup = ENV['XDG_CONFIG_HOME']