You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"abcde" =~ m{
\A
(?{ say "branch 1.1" })
a
(b (?{ say "branch 2.1: b" }) | . (?{ say "branch 2.2: ." }))
(*THEN)
(*FAIL)
|
\A
(?{ say "branch 1.2" })
a
}x;
outputs
branch 1.1
branch 2.1: b
branch 2.2: .
branch 1.2
(The line branch 2.2: . shouldn't be printed.)
The issue is that the regex engine backtracks into the inner branch 2 while it shouldn't backtrack at all in between the start of the current alternation (or whole match if the top level isn't an alternation) and the predicate (*THEN) if the control flow in the match attempt went after (*THEN), which it has in this case.
(*THEN) also fails to work properly in the case where the top level isn't an alternation:
"abcde" =~ m{
\A
(?{ say "start" })
a
(b (?{ say "branch 2.1: b" }) | . (?{ say "branch 2.2: ." }))
(*THEN)
(*FAIL)
}x;
which outputs
start
branch 2.1: b
branch 2.2: .
again the line branch 2.2: . should not be printed.
On a side note, do we need to have github repository privileges to remove the "Needs Triage" label and add new ones?
I believe the answer to those two questions is "Yes." "Needs Triage" is, I believe, automatically added to every new Issue. Other labels, e.g., "documentation," may be added if you select one of the other options at https://github.com/Perl/perl5/issues/new/choose.
If you have further questions about this or want to discuss it further, that discussion should not take place inside this or any GH issue. It's a policy issue, and so it should be discussed on the perl5-porters mailing list.
This code
outputs
(The line
branch 2.2: .
shouldn't be printed.)The issue is that the regex engine backtracks into the inner branch 2 while it shouldn't backtrack at all in between the start of the current alternation (or whole match if the top level isn't an alternation) and the predicate
(*THEN)
if the control flow in the match attempt went after(*THEN)
, which it has in this case.(*THEN)
also fails to work properly in the case where the top level isn't an alternation:which outputs
again the line
branch 2.2: .
should not be printed.This was already reported in the issue #17069.
In these 2 test cases, replacing
(*THEN)
by(*PRUNE)
does cut the backtracking normally.The text was updated successfully, but these errors were encountered: