summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--string.c4
-rw-r--r--test/ruby/test_string.rb3
2 files changed, 6 insertions, 1 deletions
diff --git a/string.c b/string.c
index fcaf280baa..2805b4d2aa 100644
--- a/string.c
+++ b/string.c
@@ -8087,7 +8087,9 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
struct re_registers *regs;
while ((end = rb_reg_search(spat, str, start, 0)) >= 0) {
- regs = RMATCH_REGS(rb_backref_get());
+ VALUE match = rb_backref_get();
+ if (!result) rb_match_busy(match);
+ regs = RMATCH_REGS(match);
if (start == end && BEG(0) == END(0)) {
if (!ptr) {
SPLIT_STR(0, 0);
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 611bb797bc..7ae3bf272e 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1779,6 +1779,9 @@ CODE
result = []; "".split(//, 1) {|s| result << s}
assert_equal([], result)
+
+ result = []; "aaa,bbb,ccc,ddd".split(/,/) {|s| result << s.gsub(/./, "A")}
+ assert_equal(["AAA"]*4, result)
ensure
EnvUtil.suppress_warning {$; = fs}
end