diff options
-rw-r--r-- | string.c | 6 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 17 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 20 insertions, 5 deletions
@@ -7255,7 +7255,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) else if (lim == 1) { if (RSTRING_LEN(str) == 0) return rb_ary_new2(0); - return rb_ary_new3(1, str); + return rb_ary_new3(1, rb_str_dup(str)); } i = 1; } @@ -8928,7 +8928,7 @@ rb_str_partition(VALUE str, VALUE sep) pos = rb_reg_search(sep, str, 0, 0); if (pos < 0) { failed: - return rb_ary_new3(3, str, str_new_empty(str), str_new_empty(str)); + return rb_ary_new3(3, rb_str_dup(str), str_new_empty(str), str_new_empty(str)); } sep = rb_str_subpat(str, sep, INT2FIX(0)); if (pos == 0 && RSTRING_LEN(sep) == 0) goto failed; @@ -8981,7 +8981,7 @@ rb_str_rpartition(VALUE str, VALUE sep) pos = rb_str_rindex(str, sep, pos); } if (pos < 0) { - return rb_ary_new3(3, str_new_empty(str), str_new_empty(str), str); + return rb_ary_new3(3, str_new_empty(str), str_new_empty(str), rb_str_dup(str)); } if (regex) { sep = rb_reg_nth_match(0, rb_backref_get()); diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 191d5fc705..6a055f1330 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1479,6 +1479,11 @@ CODE } end + def test_split_dupped + s = "abc" + s.split("b", 1).map(&:upcase!) + assert_equal("abc", s) + end def test_squeeze assert_equal(S("abc"), S("aaabbbbccc").squeeze) assert_equal(S("aa bb cc"), S("aa bb cc").squeeze(S(" "))) @@ -2223,7 +2228,12 @@ CODE end assert_equal(["\u30E6\u30FC\u30B6", "@", "\u30C9\u30E1.\u30A4\u30F3"], - "\u30E6\u30FC\u30B6@\u30C9\u30E1.\u30A4\u30F3".partition(/[@.]/)) + "\u30E6\u30FC\u30B6@\u30C9\u30E1.\u30A4\u30F3".partition(/[@.]/)) + + bug = '[ruby-core:82911]' + hello = "hello" + hello.partition("hi").map(&:upcase!) + assert_equal("hello", hello, bug) end def test_rpartition @@ -2243,6 +2253,11 @@ CODE bug8138 = '[ruby-dev:47183]' assert_equal(["\u30E6\u30FC\u30B6@\u30C9\u30E1", ".", "\u30A4\u30F3"], "\u30E6\u30FC\u30B6@\u30C9\u30E1.\u30A4\u30F3".rpartition(/[@.]/), bug8138) + + bug = '[ruby-core:82911]' + hello = "hello" + hello.rpartition("hi").map(&:upcase!) + assert_equal("hello", hello, bug) end def test_setter @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.4.4" #define RUBY_RELEASE_DATE "2018-03-06" -#define RUBY_PATCHLEVEL 251 +#define RUBY_PATCHLEVEL 252 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 3 |