Fix multiplex backreferencs near end of string in regexp match

Idea from Jirka Marsik.

Fixes [Bug #18631]
This commit is contained in:
Jeremy Evans 2022-03-24 11:05:12 -07:00
Родитель 173a6b6a80
Коммит 6d3f447aec
2 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -1178,11 +1178,13 @@ static int string_cmp_ic(OnigEncoding enc, int case_fold_flag,
# define DATA_ENSURE_CHECK1 (s < right_range)
# define DATA_ENSURE_CHECK(n) (s + (n) <= right_range)
# define DATA_ENSURE(n) if (s + (n) > right_range) goto fail
# define DATA_ENSURE_CONTINUE(n) if (s + (n) > right_range) continue
# define ABSENT_END_POS right_range
#else
# define DATA_ENSURE_CHECK1 (s < end)
# define DATA_ENSURE_CHECK(n) (s + (n) <= end)
# define DATA_ENSURE(n) if (s + (n) > end) goto fail
# define DATA_ENSURE_CONTINUE(n) if (s + (n) > end) continue
# define ABSENT_END_POS end
#endif /* USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE */
@ -2645,7 +2647,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
? STACK_AT(mem_end_stk[mem])->u.mem.pstr
: (UChar* )((void* )mem_end_stk[mem]));
n = pend - pstart;
DATA_ENSURE(n);
DATA_ENSURE_CONTINUE(n);
sprev = s;
swork = s;
STRING_CMP_VALUE(pstart, swork, n, is_fail);
@ -2684,7 +2686,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
? STACK_AT(mem_end_stk[mem])->u.mem.pstr
: (UChar* )((void* )mem_end_stk[mem]));
n = pend - pstart;
DATA_ENSURE(n);
DATA_ENSURE_CONTINUE(n);
sprev = s;
swork = s;
STRING_CMP_VALUE_IC(case_fold_flag, pstart, &swork, n, end, is_fail);

Просмотреть файл

@ -1422,6 +1422,12 @@ class TestRegexp < Test::Unit::TestCase
end
end
def test_bug18631
assert_kind_of MatchData, /(?<x>a)(?<x>aa)\k<x>/.match("aaaaa")
assert_kind_of MatchData, /(?<x>a)(?<x>aa)\k<x>/.match("aaaa")
assert_kind_of MatchData, /(?<x>a)(?<x>aa)\k<x>/.match("aaaab")
end
# This assertion is for porting x2() tests in testpy.py of Onigmo.
def assert_match_at(re, str, positions, msg = nil)
re = Regexp.new(re) unless re.is_a?(Regexp)