string.c(rb_str_split_m): Handle /\K/ correctly
Use BEG(0) instead of the result of rb_reg_search to handle the cases when the separator Regexp contains /\K/ (lookbehind) operator. Fixes [Bug #17113]
This commit is contained in:
parent
66efe37311
commit
e79cdcf61b
Notes:
git
2020-08-12 10:02:06 +09:00
3
string.c
3
string.c
@ -8216,11 +8216,12 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||||||
struct re_registers *regs;
|
struct re_registers *regs;
|
||||||
VALUE match = 0;
|
VALUE match = 0;
|
||||||
|
|
||||||
for (; (end = rb_reg_search(spat, str, start, 0)) >= 0;
|
for (; rb_reg_search(spat, str, start, 0) >= 0;
|
||||||
(match ? (rb_match_unbusy(match), rb_backref_set(match)) : (void)0)) {
|
(match ? (rb_match_unbusy(match), rb_backref_set(match)) : (void)0)) {
|
||||||
match = rb_backref_get();
|
match = rb_backref_get();
|
||||||
if (!result) rb_match_busy(match);
|
if (!result) rb_match_busy(match);
|
||||||
regs = RMATCH_REGS(match);
|
regs = RMATCH_REGS(match);
|
||||||
|
end = BEG(0);
|
||||||
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);
|
||||||
|
@ -1838,6 +1838,11 @@ CODE
|
|||||||
assert_equal("abc", s)
|
assert_equal("abc", s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_split_lookbehind
|
||||||
|
assert_equal([S("ab"), S("d")], S("abcd").split(/(?<=b)c/))
|
||||||
|
assert_equal([S("ab"), S("d")], S("abcd").split(/b\Kc/))
|
||||||
|
end
|
||||||
|
|
||||||
def test_squeeze
|
def test_squeeze
|
||||||
assert_equal(S("abc"), S("aaabbbbccc").squeeze)
|
assert_equal(S("abc"), S("aaabbbbccc").squeeze)
|
||||||
assert_equal(S("aa bb cc"), S("aa bb cc").squeeze(S(" ")))
|
assert_equal(S("aa bb cc"), S("aa bb cc").squeeze(S(" ")))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user