mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
[ruby/reline] Fix Reline crash with invalid encoding history
(https://github.com/ruby/reline/pull/751)
e9d4b37e34
This commit is contained in:
parent
ec230ac643
commit
e320da6097
5 changed files with 57 additions and 4 deletions
|
@ -266,6 +266,15 @@ class Reline::History::Test < Reline::TestCase
|
|||
assert_equal 5, history.size
|
||||
end
|
||||
|
||||
def test_history_encoding_conversion
|
||||
history = history_new
|
||||
text1 = String.new("a\u{65535}b\xFFc", encoding: Encoding::UTF_8)
|
||||
text2 = String.new("d\xFFe", encoding: Encoding::Shift_JIS)
|
||||
history.push(text1.dup, text2.dup)
|
||||
expected = [text1, text2].map { |s| s.encode(Reline.encoding_system_needs, invalid: :replace, undef: :replace) }
|
||||
assert_equal(expected, history.to_a)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def history_new(history_size: 10)
|
||||
|
|
|
@ -89,4 +89,32 @@ class Reline::Unicode::Test < Reline::TestCase
|
|||
assert_equal ["\e[31mc\1ABC\2d\e[0mef", 2, 4], Reline::Unicode.take_mbchar_range("\e[31mabc\1ABC\2d\e[0mefghi", 2, 4)
|
||||
assert_equal ["\e[41m \e[42mい\e[43m ", 1, 4], Reline::Unicode.take_mbchar_range("\e[41mあ\e[42mい\e[43mう", 1, 4, padding: true)
|
||||
end
|
||||
|
||||
def test_encoding_conversion
|
||||
texts = [
|
||||
String.new("invalid\xFFutf8", encoding: 'utf-8'),
|
||||
String.new("invalid\xFFsjis", encoding: 'sjis'),
|
||||
"utf8#{33111.chr('sjis')}convertible",
|
||||
"utf8#{33222.chr('sjis')}inconvertible",
|
||||
"sjis->utf8->sjis#{60777.chr('sjis')}irreversible"
|
||||
]
|
||||
utf8_texts = [
|
||||
'invalid<69>utf8',
|
||||
'invalid<69>sjis',
|
||||
'utf8仝convertible',
|
||||
'utf8<66>inconvertible',
|
||||
'sjis->utf8->sjis劦irreversible'
|
||||
]
|
||||
sjis_texts = [
|
||||
'invalid?utf8',
|
||||
'invalid?sjis',
|
||||
"utf8#{33111.chr('sjis')}convertible",
|
||||
'utf8?inconvertible',
|
||||
"sjis->utf8->sjis#{60777.chr('sjis')}irreversible"
|
||||
]
|
||||
assert_equal(utf8_texts, texts.map { |s| Reline::Unicode.safe_encode(s, 'utf-8') })
|
||||
assert_equal(utf8_texts, texts.map { |s| Reline::Unicode.safe_encode(s, Encoding::UTF_8) })
|
||||
assert_equal(sjis_texts, texts.map { |s| Reline::Unicode.safe_encode(s, 'sjis') })
|
||||
assert_equal(sjis_texts, texts.map { |s| Reline::Unicode.safe_encode(s, Encoding::Windows_31J) })
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue