Skip to content

Commit f79b4c8

Browse files
committed
Fixed an exception occurred when ambiguous width character was passed to #calculate_width [Bug #17405]
1 parent 723c6e1 commit f79b4c8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/reline.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Core
3636
attr_accessor :config
3737
attr_accessor :key_stroke
3838
attr_accessor :line_editor
39-
attr_accessor :ambiguous_width
39+
attr_writer :ambiguous_width
4040
attr_accessor :last_incremental_search
4141
attr_reader :output
4242

@@ -356,9 +356,14 @@ def readline(prompt = '', add_hist = false)
356356
end
357357
end
358358

359+
def ambiguous_width
360+
may_req_ambiguous_char_width unless defined? @ambiguous_width
361+
@ambiguous_width
362+
end
363+
359364
private def may_req_ambiguous_char_width
360365
@ambiguous_width = 2 if Reline::IOGate == Reline::GeneralIO or STDOUT.is_a?(File)
361-
return if ambiguous_width
366+
return if @ambiguous_width
362367
Reline::IOGate.move_cursor_column(0)
363368
begin
364369
output.write "\u{25bd}"

test/reline/test_unicode.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ def setup
99
def test_get_mbchar_width
1010
assert_equal Reline.ambiguous_width, Reline::Unicode.get_mbchar_width('é')
1111
end
12+
13+
def test_ambiguous_width
14+
assert_equal 2, Reline::Unicode.calculate_width('√', true)
15+
end
1216
end

0 commit comments

Comments
 (0)