summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-02-15 00:27:51 +0900
committeraycabta <aycabta@gmail.com>2021-02-21 06:41:03 +0900
commitdc9e33016c289f54407239b58e3e4669fdd442ad (patch)
tree70409407c32c607497459c65fd0db31bb062f226
parentb88be1009435ff10c582c727f71995f9c78f2885 (diff)
[ruby/reline] Return 1 when char width not found
This fixes ruby/reline#261. https://github.com/ruby/reline/commit/3cf1213014
-rw-r--r--lib/reline/unicode.rb1
-rw-r--r--test/reline/test_key_actor_emacs.rb8
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/reline/unicode.rb b/lib/reline/unicode.rb
index 9b5ddc4622..7dbe8a12a5 100644
--- a/lib/reline/unicode.rb
+++ b/lib/reline/unicode.rb
@@ -108,6 +108,7 @@ class Reline::Unicode
end
m = mbchar.encode(Encoding::UTF_8).match(MBCharWidthRE)
case
+ when m.nil? then 1 # TODO should be U+FFFD � REPLACEMENT CHARACTER
when m[:width_2_1], m[:width_2_2] then 2
when m[:width_3] then 3
when m[:width_0] then 0
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb
index b4dc3a1bcb..947685409f 100644
--- a/test/reline/test_key_actor_emacs.rb
+++ b/test/reline/test_key_actor_emacs.rb
@@ -2280,6 +2280,14 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_line(' 12345')
end
+ def test_input_unknown_char
+ input_keys('͸') # U+0378 (unassigned)
+ assert_line('͸')
+ assert_byte_pointer_size('͸')
+ assert_cursor(1)
+ assert_cursor_max(1)
+ end
+
=begin # TODO: move KeyStroke instance from Reline to LineEditor
def test_key_delete
input_keys('ab')