From 778634f778a029476fb85463462848c0341f8e6b Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 27 Dec 2019 16:02:07 +0900 Subject: [PATCH] Drop an invalid char as UTF-8 --- lib/reline/line_editor.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 75af50a908..3f6d7817db 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1091,6 +1091,11 @@ class Reline::LineEditor private def ed_insert(key) if key.instance_of?(String) + begin + key.encode(Encoding::UTF_8) + rescue Encoding::UndefinedConversionError + return + end width = Reline::Unicode.get_mbchar_width(key) if @cursor == @cursor_max @line += key @@ -1101,6 +1106,11 @@ class Reline::LineEditor @cursor += width @cursor_max += width else + begin + key.chr.encode(Encoding::UTF_8) + rescue Encoding::UndefinedConversionError + return + end if @cursor == @cursor_max @line += key.chr else