Fix bug for groups like (a)*+ (possessive, zero minimum) when the ovector was

too small to capture.
This commit is contained in:
Philip.Hazel 2015-02-11 10:06:09 +00:00
parent 154bc83cb5
commit 3d9cc76a52
4 changed files with 89 additions and 68 deletions

View File

@ -76,6 +76,10 @@ locales that can be used.
capturing group number without parentheses, the last character was incorrectly
literally included at the end of the replacement string.
15. A possessive capturing group such as (a)*+ with a minimum repeat of zero
failed to allow the zero-repeat case if pcre2_match() was called with an
ovector too small to capture the group.
Version 10.00 05-January-2015
-----------------------------

View File

@ -1149,7 +1149,8 @@ for (;;)
different. The end of these brackets will always be OP_KETRPOS, which
returns MATCH_KETRPOS without going further in the pattern. By this means
we can handle the group by iteration rather than recursion, thereby
reducing the amount of stack needed. */
reducing the amount of stack needed. If the ovector is too small for
capturing, treat as non-capturing. */
case OP_CBRAPOS:
case OP_SCBRAPOS:
@ -1158,9 +1159,8 @@ for (;;)
POSSESSIVE_CAPTURE:
number = GET2(ecode, 1+LINK_SIZE);
offset = number << 1;
if (offset >= mb->offset_max) goto POSSESSIVE_NON_CAPTURE;
if (offset < mb->offset_max)
{
matched_once = FALSE;
code_offset = (int)(ecode - mb->start_code);
@ -1229,15 +1229,7 @@ for (;;)
ecode += 1 + LINK_SIZE;
break;
}
RRETURN(MATCH_NOMATCH);
}
/* FALL THROUGH ... Insufficient room for saving captured contents. Treat
as a non-capturing bracket. */
/* VVVVVVVVVVVVVVVVVVVVVVVVV */
/* VVVVVVVVVVVVVVVVVVVVVVVVV */
/* Non-capturing possessive bracket with unlimited repeat. We come here
from BRAZERO with allow_zero = TRUE. The code is similar to the above,

8
testdata/testinput2 vendored
View File

@ -4164,4 +4164,12 @@ a random value. /Ix
** Failers
356
'^(a)*+(\w)'
g
g\=ovector=1
'^(?:a)*+(\w)'
g
g\=ovector=1
# End of testinput2

17
testdata/testoutput2 vendored
View File

@ -13933,4 +13933,21 @@ No match
356
No match
'^(a)*+(\w)'
g
0: g
1: <unset>
2: g
g\=ovector=1
Matched, but too many substrings
0: g
'^(?:a)*+(\w)'
g
0: g
1: g
g\=ovector=1
Matched, but too many substrings
0: g
# End of testinput2