1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Occupy match data

* string.c (rb_str_split_m): occupy match data not to be modified
  during yielding the block.  [Bug #16024]
This commit is contained in:
Nobuyoshi Nakada 2019-07-27 21:54:34 +09:00
parent e3b613a669
commit f1b76ea63c
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 6 additions and 1 deletions

View file

@ -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);

View file

@ -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