Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/reline/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def read_lines(lines, file = nil)
if_stack = []

lines.each_with_index do |line, no|
# Even after encoding conversion, we need to verify the encoding is valid
# as some invalid byte sequences might pass through the conversion.
unless line.valid_encoding?
raise InvalidInputrc, "#{file}:#{no + 1}: can't be converted to the locale #{Reline.encoding_system_needs.name}"
end
next if line.match(/\A\s*#/)

no += 1
Expand Down
17 changes: 17 additions & 0 deletions test/reline/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,21 @@ def test_reload
@config.reload
assert_equal '@', @config.emacs_mode_string
end

def test_invalid_byte_sequence_inputrc
lines = [
"set vi-cmd-mode-string\n",
"$if Ruby\n",
" \"\C-a\": \"Ruby\"\n",
"$else \"\xFF\"\n".dup.force_encoding(Reline.encoding_system_needs), # Invalid byte sequence
" \"\C-b\": \"NotRuby\"\n",
"$endif\n"
]

e = assert_raise(Reline::Config::InvalidInputrc) do
@config.read_lines(lines, "INPUTRC")
end

assert_equal "INPUTRC:4: can't be converted to the locale #{Reline.encoding_system_needs}", e.message
end
end