diff options
author | Yves Orton <demerphq@gmail.com> | 2023-01-09 22:34:13 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-03-13 21:26:08 +0800 |
commit | acababb42be12ff2986b73c1bfa963b70bb5d54e (patch) | |
tree | dc8cc4980e6fe3de0c686cc641dbbe37d1e8e961 /t/re | |
parent | 05b13cf680588a26de64f13d2b3be385e17624bc (diff) | |
download | perl-acababb42be12ff2986b73c1bfa963b70bb5d54e.tar.gz |
regexec.c - teach BRANCH and BRANCHJ nodes to reset capture buffers
In /((a)(b)|(a))+/ we should not end up with $2 and $4 being set at
the same time. When a branch fails it should reset any capture buffers
that might be touched by its branch.
We change BRANCH and BRANCHJ to store the number of parens before the
branch, and the number of parens after the branch was completed. When
a BRANCH operation fails, we clear the buffers it contains before we
continue on.
It is a bit more complex than it should be because we have BRANCHJ
and BRANCH. (One of these days we should merge them together.)
This is also made somewhat more complex because TRIE nodes are actually
branches, and may need to track capture buffers also, at two levels.
The overall TRIE op, and for jump tries especially where we emulate
the behavior of branches. So we have to do the same clearing logic if
a trie branch fails as well.
Diffstat (limited to 't/re')
-rw-r--r-- | t/re/pat.t | 24 | ||||
-rw-r--r-- | t/re/re_tests | 11 |
2 files changed, 21 insertions, 14 deletions
diff --git a/t/re/pat.t b/t/re/pat.t index b837157c42..95070b2290 100644 --- a/t/re/pat.t +++ b/t/re/pat.t @@ -2427,7 +2427,6 @@ SKIP: }, 'ok', {}, 'gh20826: test regex save stack overflow'); } { - local $::TODO = "Not Yet Implemented"; my ($x, $y); ok( "aaa" =~ /(?:(a)?\1)+/, "GH Issue #18865 'aaa' - pattern matches"); @@ -2435,26 +2434,33 @@ SKIP: ok( "aaa" =~ /(?:((?{})a)?\1)+/, "GH Issue #18865 'aaa' - deoptimized pattern matches"); $y = "($-[0],$+[0])"; - is( $y, $x, - "GH Issue #18865 'aaa' - test optimization"); - + { + local $::TODO = "Not Yet Implemented"; + is( $y, $x, + "GH Issue #18865 'aaa' - test optimization"); + } ok( "ababab" =~ /(?:(?:(ab))?\1)+/, "GH Issue #18865 'ababab' - pattern matches"); $x = "($-[0],$+[0])"; ok( "ababab" =~ /(?:(?:((?{})ab))?\1)+/, "GH Issue #18865 'ababab' - deoptimized pattern matches"); $y = "($-[0],$+[0])"; - is( $y, $x, - "GH Issue #18865 'ababab' - test optimization"); - + { + local $::TODO = "Not Yet Implemented"; + is( $y, $x, + "GH Issue #18865 'ababab' - test optimization"); + } ok( "XaaXbbXb" =~ /(?:X([ab])?\1)+/, "GH Issue #18865 'XaaXbbXb' - pattern matches"); $x = "($-[0],$+[0])"; ok( "XaaXbbXb" =~ /(?:X((?{})[ab])?\1)+/, "GH Issue #18865 'XaaXbbXb' - deoptimized pattern matches"); $y = "($-[0],$+[0])"; - is( $y, $x, - "GH Issue #18865 'XaaXbbXb' - test optimization"); + { + local $::TODO = "Not Yet Implemented"; + is( $y, $x, + "GH Issue #18865 'XaaXbbXb' - test optimization"); + } } } # End of sub run_tests diff --git a/t/re/re_tests b/t/re/re_tests index 7379a39787..bfccaa04ed 100644 --- a/t/re/re_tests +++ b/t/re/re_tests @@ -478,7 +478,7 @@ a(?:b|c|d)+(.) acdbcdbe y $1 e a(?:b|c|d){2}(.) acdbcdbe y $1 b a(?:b|c|d){4,5}(.) acdbcdbe y $1 b a(?:b|c|d){4,5}?(.) acdbcdbe y $1 d -((foo)|(bar))* foobar Ty $1-$2-$3 bar--bar # was bar-foo-bar prior to 5.37.7 +((foo)|(bar))* foobar y $1-$2-$3 bar--bar # was bar-foo-bar prior to 5.37.7 :(?: - c - Sequence (? incomplete a(?:b|c|d){6,7}(.) acdbcdbe y $1 e a(?:b|c|d){6,7}?(.) acdbcdbe y $1 e @@ -501,7 +501,7 @@ a(?:b|(c|e){1,2}?|d)+?(.) ace y $1$2 ce ((a{4})+) aaaaaaaaa y $1 aaaaaaaa (((aa){2})+) aaaaaaaaaa y $1 aaaaaaaa (((a{2}){2})+) aaaaaaaaaa y $1 aaaaaaaa -(?:(f)(o)(o)|(b)(a)(r))* foobar Ty $1:$2:$3:$4:$5:$6 :::b:a:r +(?:(f)(o)(o)|(b)(a)(r))* foobar y $1:$2:$3:$4:$5:$6 :::b:a:r (?<=a)b ab y $& b (?<=af?)b ab y $& b (?<=a)b cb n - - @@ -964,8 +964,8 @@ tt+$ xxxtt y - - (?i) y - - (?a:((?u)\w)\W) \xC0\xC0 y $& \xC0\xC0 '(?!\A)x'm a\nxb\n y - - -^(a(b)?)+$ aba y -$1-$2- -a-- # !normal -^(aa(bb)?)+$ aabbaa y -$1-$2- -aa-- # !normal +^(a(b)?)+$ aba y -$1-$2- -a-- +^(aa(bb)?)+$ aabbaa y -$1-$2- -aa-- '^.{9}abc.*\n'm 123\nabcabcabcabc\n y - - ^(a)?a$ a y -$1- -- ^(a)?(?(1)a|b)+$ a n - - @@ -2139,7 +2139,8 @@ AB\s+\x{100} AB \x{100}X y - - /(([ab]+)|([cd]+)|([ef]+))+/ ace y $1-$2-$3-$4=$& e---e=ace /(([ab]+)|([cd]+)|([ef]+))+/ aceb Ty $1-$2-$3-$4=$& b-b--=aceb /(([ab]+)|([cd]+)|([ef]+))+/ acebd Ty $1-$2-$3-$4=$& d--d-=acebd -/(([ab]+)|([cd]+)|([ef]+))+/ acebdf Ty $1-$2-$3-$4=$& f---f=acebdf +/(([ab]+)|([cd]+)|([ef]+))+/ acebdf y $1-$2-$3-$4=$& f---f=acebdf +/((a)(b)(c)|(a)(b)|(a))+/ abcaba y $1+$2-$3-$4+$5-$6+$7=$& a+--+-+a=abcaba # Keep these lines at the end of the file # pat string y/n/etc expr expected-expr skip-reason comment # vim: softtabstop=0 noexpandtab |