Skip to content

Commit cf372fc

Browse files
committed
ensure reline's encoding is used when reading inputrc character values
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 => #<Encoding:UTF-8> > 127864.ord.chr(Reline::IOGate.encoding) => "🍸" ```
1 parent 3a8c605 commit cf372fc

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/reline/config.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,8 @@ def bind_variable(name, value)
291291
end
292292

293293
def retrieve_string(str)
294-
if str =~ /\A"(.*)"\z/
295-
parse_keyseq($1).map(&:chr).join
296-
else
297-
parse_keyseq(str).map(&:chr).join
298-
end
294+
str = $1 if str =~ /\A"(.*)"\z/
295+
parse_keyseq(str).map { |c| c.chr(Reline::IOGate.encoding) }.join
299296
end
300297

301298
def bind_key(key, func_name)

test/reline/test_config.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ def test_inputrc
286286
ENV['INPUTRC'] = inputrc_backup
287287
end
288288

289+
def test_inputrc_with_utf
290+
@config.read_lines(<<~'LINES'.lines)
291+
set editing-mode vi
292+
set vi-cmd-mode-string 🍸
293+
set vi-ins-mode-string 🍶
294+
LINES
295+
assert_equal @config.vi_cmd_mode_string, "🍸"
296+
assert_equal @config.vi_ins_mode_string, "🍶"
297+
end
298+
289299
def test_xdg_config_home
290300
home_backup = ENV['HOME']
291301
xdg_config_home_backup = ENV['XDG_CONFIG_HOME']

0 commit comments

Comments
 (0)