From 6d742295f3f75630234c393484445fa287cf02a1 Mon Sep 17 00:00:00 2001 From: nagachika Date: Mon, 5 Mar 2018 16:11:30 +0000 Subject: merge revision(s) 60000,60001,60002: [Backport #13925] dup String#partition return value * string.c (rb_str_partition): return duplicated receiver, when no splits. [ruby-core:82911] [Bug#13925] Author: Seiei Miyagi dup String#rpartition return value * string.c (rb_str_rpartition): return duplicated receiver, when no splits. [ruby-core:82911] [Bug#13925] Author: Seiei Miyagi dup String#split return value * string.c (rb_str_split): return duplicated receiver, when no splits. patched by tompng (tomoya ishida) in [ruby-core:82911], and the test case by Seiei Miyagi . [Bug#13925] [Fix GH-1705] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 221d50eedf..0a5f802452 100644 --- a/string.c +++ b/string.c @@ -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()); -- cgit v1.2.3