summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-08-17 15:52:34 +0900
committerGitHub <[email protected]>2019-08-17 15:52:34 +0900
commit277c91e94cc1e3df52c28048859a267335571d6c (patch)
tree4a6c18e059060d4c09d8fb292e11444c43bdd1a4 /test
parentb55e72b2d67c1042a5170f4cc9cac809f4ed2c90 (diff)
parentbc272730874b5f0e22f0b7126ec46bc761d335b1 (diff)
downloadmruby-277c91e94cc1e3df52c28048859a267335571d6c.tar.gz
mruby-277c91e94cc1e3df52c28048859a267335571d6c.zip
Merge pull request #4625 from dearblue/rindex-broken-utf8
Fix `String#rindex` with invalid UTF-8 string
Diffstat (limited to 'test')
-rw-r--r--test/t/string.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/test/t/string.rb b/test/t/string.rb
index 46cbe6e2a..7e3c327b1 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -557,10 +557,16 @@ end
assert('String#rindex(UTF-8)', '15.2.10.5.31') do
str = "こんにちは世界!\nこんにちは世界!"
- assert_nil str.index('さ')
- assert_equal 3, str.index('ち')
- assert_equal 12, str.index('ち', 10)
- assert_equal nil, str.index("さ")
+ assert_nil str.rindex('さ')
+ assert_equal 12, str.rindex('ち')
+ assert_equal 3, str.rindex('ち', 10)
+
+ broken = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"
+ assert_nil broken.rindex("\x81") # "\x81" is a part of "☁" ("\xe2\x98\x81")
+ assert_equal 11, broken.rindex("☁")
+ assert_equal 11, broken.rindex("☁", 12)
+ assert_equal 11, broken.rindex("☁", 11)
+ assert_equal 3, broken.rindex("☁", 10)
end if UTF8STRING
# assert('String#scan', '15.2.10.5.32') do