Skip to content

Commit

Permalink
Set RXf_CHECK_ALL with RXf_RTRIM - re_intuit_start can do the entire …
Browse files Browse the repository at this point in the history
…match!
  • Loading branch information
nwc10 authored and khwilliamson committed Jun 6, 2021
1 parent ddce7ad commit 6e855fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion regcomp.c
Expand Up @@ -8494,7 +8494,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
regnode *third = OP(second) == EOS ? regnext(second) : NULL;
if (third && OP(third) == END) {
/* /[[:space:]]+\z/u */
RExC_rx->extflags |= RXf_RTRIM;
RExC_rx->extflags |= RXf_RTRIM | RXf_CHECK_ALL;
}
}

Expand Down
18 changes: 14 additions & 4 deletions regexec.c
Expand Up @@ -966,7 +966,7 @@ Perl_re_intuit_start(pTHX_
PL_colors[4], PL_colors[5], (long)(s - strbeg)) );
return s;
}
return strpos;
goto fail;
}

if (utf8_target) {
Expand Down Expand Up @@ -3699,9 +3699,19 @@ Perl_regexec_flags(pTHX_ REGEXP * const rx, char *stringarg, char *strend,
prog->lastparen = prog->lastcloseparen = 0;
RXp_MATCH_UTF8_set(prog, utf8_target);
prog->offs[0].start = s - strbeg;
prog->offs[0].end = utf8_target
? (char*)utf8_hop_forward((U8*)s, prog->minlenret, (U8 *) strend) - strbeg
: s - strbeg + prog->minlenret;
if (prog->extflags & RXf_RTRIM) {
/* Oh my, seems that until RTRIM, match via INTUIT was always
* a fixed length, given by minlenret.
* RTRIM breaks that assumption.
* For now, we just hack our known (other) match length - the
* entire string: */
prog->offs[0].end = strend - strbeg;
}
else {
prog->offs[0].end = utf8_target
? (char*)utf8_hop_forward((U8*)s, prog->minlenret, (U8 *) strend) - strbeg
: s - strbeg + prog->minlenret;
}
if ( !(flags & REXEC_NOT_FIRST) )
S_reg_set_capture_string(aTHX_ rx,
strbeg, strend,
Expand Down

0 comments on commit 6e855fb

Please sign in to comment.