summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-12-27 16:02:07 +0900
committeraycabta <aycabta@gmail.com>2019-12-27 16:02:30 +0900
commit778634f778a029476fb85463462848c0341f8e6b (patch)
treeea3dc8fa77c5682fd206c3168df5700ce3dd35be /lib
parent729b7ce27058ed4b41d5facbb6b912b8e7c6a960 (diff)
Drop an invalid char as UTF-8
Diffstat (limited to 'lib')
-rw-r--r--lib/reline/line_editor.rb10
1 files changed, 10 insertions, 0 deletions
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