ruby-changes:27851
From: knu <ko1@a...>
Date: Sun, 24 Mar 2013 18:32:17 +0900 (JST)
Subject: [ruby-changes:27851] knu:r39903 (trunk): Fix String#rpartition(/re/) against a multibyte string.
knu 2013-03-24 18:32:06 +0900 (Sun, 24 Mar 2013) New Revision: 39903 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39903 Log: 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] Modified files: trunk/ChangeLog trunk/string.c trunk/test/ruby/test_string.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39902) +++ ChangeLog (revision 39903) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Mar 24 18:29:46 2013 Akinori MUSHA <knu@i...> + + * 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 <authornari@g...> * gc.c (GC_ENABLE_LAZY_SWEEP): new macro to switch lazy sweeping Index: string.c =================================================================== --- string.c (revision 39902) +++ string.c (revision 39903) @@ -7542,9 +7542,10 @@ rb_str_rpartition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L7542 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))); } /* Index: test/ruby/test_string.rb =================================================================== --- test/ruby/test_string.rb (revision 39902) +++ test/ruby/test_string.rb (revision 39903) @@ -1998,6 +1998,9 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1998 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L2016 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/