mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/reline] Fixed an exception occurred when ambiguous width character was passed to #calculate_width [Bug #17405]
f79b4c857f
This commit is contained in:
parent
b52bc4a9c2
commit
299f5708a2
2 changed files with 11 additions and 2 deletions
|
|
@ -36,7 +36,7 @@ module Reline
|
|||
attr_accessor :config
|
||||
attr_accessor :key_stroke
|
||||
attr_accessor :line_editor
|
||||
attr_accessor :ambiguous_width
|
||||
attr_writer :ambiguous_width
|
||||
attr_accessor :last_incremental_search
|
||||
attr_reader :output
|
||||
|
||||
|
|
@ -356,9 +356,14 @@ module Reline
|
|||
end
|
||||
end
|
||||
|
||||
def ambiguous_width
|
||||
may_req_ambiguous_char_width unless defined? @ambiguous_width
|
||||
@ambiguous_width
|
||||
end
|
||||
|
||||
private def may_req_ambiguous_char_width
|
||||
@ambiguous_width = 2 if Reline::IOGate == Reline::GeneralIO or STDOUT.is_a?(File)
|
||||
return if ambiguous_width
|
||||
return if @ambiguous_width
|
||||
Reline::IOGate.move_cursor_column(0)
|
||||
begin
|
||||
output.write "\u{25bd}"
|
||||
|
|
|
|||
|
|
@ -9,4 +9,8 @@ class Reline::Unicode::Test < Reline::TestCase
|
|||
def test_get_mbchar_width
|
||||
assert_equal Reline.ambiguous_width, Reline::Unicode.get_mbchar_width('é')
|
||||
end
|
||||
|
||||
def test_ambiguous_width
|
||||
assert_equal 2, Reline::Unicode.calculate_width('√', true)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue