diff --git a/lib/reline.rb b/lib/reline.rb index 649eec574b..a41c4c1031 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -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) diff --git a/lib/reline/config.rb b/lib/reline/config.rb index ed5061f802..3e6c42df48 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -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 diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb index 56fc787b65..b6d2ec7d7e 100644 --- a/test/reline/test_config.rb +++ b/test/reline/test_config.rb @@ -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