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:
parent
e3b613a669
commit
f1b76ea63c
2 changed files with 6 additions and 1 deletions
4
string.c
4
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue