Skip to content

Commit

Permalink
gh18770: stop scanning for substrs after *COMMIT
Browse files Browse the repository at this point in the history
*ACCEPT already avoids this (because it is "ENDLIKE"), but gets a
related fix to stop scanning for start class.
  • Loading branch information
hvds committed Jun 1, 2021
1 parent 403d7eb commit 499aa13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
26 changes: 20 additions & 6 deletions regcomp.c
Expand Up @@ -6350,18 +6350,32 @@ Perl_re_printf( aTHX_ "LHS=%" UVuf " RHS=%" UVuf "\n",
*(data->last_closep) = ARG(scan);
}
else if (OP(scan) == EVAL) {
if (data)
data->flags |= SF_HAS_EVAL;
if (data)
data->flags |= SF_HAS_EVAL;
}
else if ( PL_regkind[OP(scan)] == ENDLIKE ) {
if (flags & SCF_DO_SUBSTR) {
scan_commit(pRExC_state, data, minlenp, is_inf);
flags &= ~SCF_DO_SUBSTR;
}
if (data && OP(scan)==ACCEPT) {
data->flags |= SCF_SEEN_ACCEPT;
if (stopmin > min)
stopmin = min;
if (OP(scan)==ACCEPT) {
/* m{(*ACCEPT)x} does not have to start with 'x' */
flags &= ~SCF_DO_STCLASS;
if (data) {
data->flags |= SCF_SEEN_ACCEPT;
if (stopmin > min)
stopmin = min;
}
}
}
else if (OP(scan) == COMMIT) {
/* gh18770: m{abc(*COMMIT)xyz} must fail on "abc abcxyz", so we
* must not end up with "abcxyz" as a fixed substring else we'll
* skip straight to attempting to match at offset 4.
*/
if (flags & SCF_DO_SUBSTR) {
scan_commit(pRExC_state, data, minlenp, is_inf);
flags &= ~SCF_DO_SUBSTR;
}
}
else if (OP(scan) == LOGICAL && scan->flags == 2) /* Embedded follows */
Expand Down
5 changes: 5 additions & 0 deletions t/re/opt.t
Expand Up @@ -268,3 +268,8 @@ acdef|bcdeg 5 1+cde - Tanchored,stclass=~[ab]
a(b){2,3}c 4 -abb 1+bbc
a(b|bb)c 3 -ab 1-bc Tfloating,Tfloating min offset
a(b|bb){2}c 4 -abb 1-bbc Tanchored,Tfloating,Tfloating min offset
abc(*COMMIT)xyz 6 0+abc - -
abc(*ACCEPT)xyz 3 0+abc - -
# Must not have stclass=[x]
(*ACCEPT)xyz 0 - - -

0 comments on commit 499aa13

Please sign in to comment.