summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2023-08-25 00:52:53 +0900
committerNobuyoshi Nakada <[email protected]>2023-08-26 08:58:02 +0900
commitb054c2fe06598f1141fdc337b10046f41f0e227c (patch)
treede3725523fcaf4aa1e0f1bdcf04c152fab5e01d8 /test/ruby
parent808b06708884bf928b2e9c23ed5dcbbdf6665972 (diff)
[Bug #19784] Fix behaviors against prefix with broken encoding
- String#start_with? - String#delete_prefix - String#delete_prefix!
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8296
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_string.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index e69c66be40..1d8902baf1 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1938,6 +1938,8 @@ CODE
assert_send([S("hello"), :start_with?, S("hel")])
assert_not_send([S("hello"), :start_with?, S("el")])
assert_send([S("hello"), :start_with?, S("el"), S("he")])
+ assert_send([S("\xFF\xFE"), :start_with?, S("\xFF")])
+ assert_not_send([S("\u{c4}"), :start_with?, S("\xC3")])
bug5536 = '[ruby-core:40623]'
assert_raise(TypeError, bug5536) {S("str").start_with? :not_convertible_to_string}
@@ -2930,6 +2932,7 @@ CODE
assert_equal("\x95\x5c".force_encoding("Shift_JIS"), s.delete_prefix("\x95"))
assert_equal("\x95\x5c".force_encoding("Shift_JIS"), s)
+ assert_equal("\xFE", S("\xFF\xFE").delete_prefix("\xFF"))
end
def test_delete_prefix_clear_coderange
@@ -2978,6 +2981,9 @@ CODE
assert_equal(nil, s.delete_prefix!("\xe3"))
assert_equal("\xe3\x81\x82", s)
+ s = S("\xFF\xFE")
+ assert_equal("\xFE", s.delete_prefix!("\xFF"))
+ assert_equal("\xFE", s)
end
def test_delete_prefix_bang_clear_coderange