aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--string.c2
-rw-r--r--test/ruby/test_string.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/string.c b/string.c
index ad19595f67..7e7ae7f0a8 100644
--- a/string.c
+++ b/string.c
@@ -7371,7 +7371,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;
}
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 08dc806380..b1f3c3cfcb 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1686,6 +1686,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(" ")))