From b0cc46b484028b65b3306e9d19803e49c7b7cd58 Mon Sep 17 00:00:00 2001 From: aycabta Date: Tue, 20 Apr 2021 12:00:08 +0900 Subject: [ruby/reline] The config file must accept any character encoding In Japan, so many programmers used EUC-JP to write text files that contain Japanese. Many .inputrc files which contain EUC-JP are still being copied and used. This commit supports the whole encoding of what user set including UTF-8. ref. https://github.com/ruby/reline/pull/280 https://github.com/ruby/reline/commit/0b45022e16 --- lib/reline/config.rb | 5 ++++- lib/reline/general_io.rb | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/reline') diff --git a/lib/reline/config.rb b/lib/reline/config.rb index dd81a23ea7..ed5061f802 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -158,6 +158,9 @@ class Reline::Config end def read_lines(lines, file = nil) + if lines.first.encoding != Reline.encoding_system_needs + lines = lines.map { |l| l.encode(Reline.encoding_system_needs) } + end conditions = [@skip_section, @if_stack] @skip_section = nil @if_stack = [] @@ -293,7 +296,7 @@ class Reline::Config def retrieve_string(str) str = $1 if str =~ /\A"(.*)"\z/ - parse_keyseq(str).map { |c| c.chr(Reline::IOGate.encoding) }.join + parse_keyseq(str).map { |c| c.chr(Reline.encoding_system_needs) }.join end def bind_key(key, func_name) diff --git a/lib/reline/general_io.rb b/lib/reline/general_io.rb index 8c8e22d2e6..4f605628a3 100644 --- a/lib/reline/general_io.rb +++ b/lib/reline/general_io.rb @@ -1,12 +1,19 @@ require 'timeout' class Reline::GeneralIO - def self.reset + def self.reset(encoding: nil) @@pasting = false + @@encoding = encoding end def self.encoding - RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external + if @@encoding + @@encoding + elsif RUBY_PLATFORM =~ /mswin|mingw/ + Encoding::UTF_8 + else + Encoding::default_external + end end def self.win? -- cgit v1.2.3