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
4
string.c
4
string.c
@ -8087,7 +8087,9 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||||||
struct re_registers *regs;
|
struct re_registers *regs;
|
||||||
|
|
||||||
while ((end = rb_reg_search(spat, str, start, 0)) >= 0) {
|
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 (start == end && BEG(0) == END(0)) {
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
SPLIT_STR(0, 0);
|
SPLIT_STR(0, 0);
|
||||||
|
@ -1779,6 +1779,9 @@ CODE
|
|||||||
|
|
||||||
result = []; "".split(//, 1) {|s| result << s}
|
result = []; "".split(//, 1) {|s| result << s}
|
||||||
assert_equal([], result)
|
assert_equal([], result)
|
||||||
|
|
||||||
|
result = []; "aaa,bbb,ccc,ddd".split(/,/) {|s| result << s.gsub(/./, "A")}
|
||||||
|
assert_equal(["AAA"]*4, result)
|
||||||
ensure
|
ensure
|
||||||
EnvUtil.suppress_warning {$; = fs}
|
EnvUtil.suppress_warning {$; = fs}
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user