1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Rescue conversion error of inputrc

This commit is contained in:
aycabta 2021-06-21 22:12:06 +09:00
parent 574c8ee9f1
commit 046fd3ac8c
3 changed files with 14 additions and 1 deletions

View file

@ -13,6 +13,8 @@ module Reline
FILENAME_COMPLETION_PROC = nil
USERNAME_COMPLETION_PROC = nil
class ConfigEncodingConversionError < StandardError; end
Key = Struct.new('Key', :char, :combined_char, :with_meta)
CursorPos = Struct.new(:x, :y)

View file

@ -159,7 +159,14 @@ class Reline::Config
def read_lines(lines, file = nil)
if lines.first.encoding != Reline.encoding_system_needs
lines = lines.map { |l| l.encode(Reline.encoding_system_needs) }
begin
lines = lines.map do |l|
l.encode(Reline.encoding_system_needs)
rescue Encoding::UndefinedConversionError
mes = "The inputrc encoded in #{lines.first.encoding.name} can't be converted to the locale #{Reline.encoding_system_needs.name}."
raise Reline::ConfigEncodingConversionError.new(mes)
end
end
end
conditions = [@skip_section, @if_stack]
@skip_section = nil

View file

@ -295,6 +295,8 @@ class Reline::Config::Test < Reline::TestCase
LINES
assert_equal '🍸', @config.vi_cmd_mode_string
assert_equal '🍶', @config.vi_ins_mode_string
rescue Reline::ConfigEncodingConversionError
# do nothing
end
def test_inputrc_with_eucjp
@ -305,6 +307,8 @@ class Reline::Config::Test < Reline::TestCase
LINES
assert_equal 'ォャッ'.encode(Reline.encoding_system_needs), @config.vi_cmd_mode_string
assert_equal '能'.encode(Reline.encoding_system_needs), @config.vi_ins_mode_string
rescue Reline::ConfigEncodingConversionError
# do nothing
end
def test_xdg_config_home