From 014236612a0be2f07ac6e645bd5a32ddbe4c8b0f Mon Sep 17 00:00:00 2001 From: knu Date: Sun, 24 Mar 2013 09:32:06 +0000 Subject: Fix String#rpartition(/re/) against a multibyte string. * string.c (rb_str_rpartition): Fix String#rpartition(/re/) against a multibyte string. [Bug #8138] [ruby-dev:47183] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ string.c | 5 +++-- test/ruby/test_string.rb | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2257af1268..49254204f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Mar 24 18:29:46 2013 Akinori MUSHA + + * string.c (rb_str_rpartition): Fix String#rpartition(/re/) + against a multibyte string. [Bug #8138] [ruby-dev:47183] + Sun Mar 24 13:42:24 2013 Narihiro Nakamura * gc.c (GC_ENABLE_LAZY_SWEEP): new macro to switch lazy sweeping diff --git a/string.c b/string.c index 80869bd720..271afa75f0 100644 --- a/string.c +++ b/string.c @@ -7542,9 +7542,10 @@ rb_str_rpartition(VALUE str, VALUE sep) if (regex) { sep = rb_reg_nth_match(0, rb_backref_get()); } - return rb_ary_new3(3, rb_str_substr(str, 0, pos), + return rb_ary_new3(3, rb_str_subseq(str, 0, pos), sep, - rb_str_substr(str,pos+str_strlen(sep,STR_ENC_GET(sep)),RSTRING_LEN(str))); + rb_str_subseq(str, pos+RSTRING_LEN(sep), + RSTRING_LEN(str)-pos-RSTRING_LEN(sep))); } /* diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index a0fb80f46e..4d9f7d95b0 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1998,6 +1998,9 @@ class TestString < Test::Unit::TestCase s = S("a:".force_encoding(enc)) assert_equal([enc]*3, s.partition("|").map(&:encoding), bug6206) end + + assert_equal(["\u30E6\u30FC\u30B6", "@", "\u30C9\u30E1.\u30A4\u30F3"], + "\u30E6\u30FC\u30B6@\u30C9\u30E1.\u30A4\u30F3".partition(/[@.]/)) end def test_rpartition @@ -2013,6 +2016,10 @@ class TestString < Test::Unit::TestCase s = S("a:".force_encoding(enc)) assert_equal([enc]*3, s.rpartition("|").map(&:encoding), bug6206) end + + bug8138 = '[ruby-dev:47183]' + assert_equal(["\u30E6\u30FC\u30B6@\u30C9\u30E1", ".", "\u30A4\u30F3"], + "\u30E6\u30FC\u30B6@\u30C9\u30E1.\u30A4\u30F3".rpartition(/[@.]/), bug8138) end def test_setter -- cgit v1.2.3