Re: [perl #23171] Regex too selfish
Hugo van der Sanden [Thu, 31 Jul 2003 18:59:43 +0000 (19:59 +0100)]
Message-Id: <200307311759.h6VHxhn06664@zen.crypt.org>

(choose the second code patch)

p4raw-id: //depot/perl@20387

regexec.c
t/op/re_tests

index db3cecb..961611b 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -3351,6 +3351,7 @@ S_regmatch(pTHX_ regnode *prog)
        {
            I32 l = 0;
            CHECKPOINT lastcp;
+           I32 lparen = *PL_reglastparen;
        
            /* We suppose that the next guy does not need
               backtracking: in particular, it is of constant length,
@@ -3435,6 +3436,8 @@ S_regmatch(pTHX_ regnode *prog)
                        }
                        if (regmatch(next))
                            sayYES;
+                       /* t/op/regexp.t test 885 fails if this is performed */
+                       /* *PL_reglastparen = lparen; */
                        REGCP_UNWIND(lastcp);
                    }
                    /* Couldn't or didn't -- move forward. */
@@ -3522,6 +3525,7 @@ S_regmatch(pTHX_ regnode *prog)
                        }
                        if (regmatch(next))
                            sayYES;
+                       *PL_reglastparen = lparen;
                        REGCP_UNWIND(lastcp);
                    }
                    /* Couldn't or didn't -- back up. */
@@ -3634,6 +3638,7 @@ S_regmatch(pTHX_ regnode *prog)
            PL_reginput = locinput;
            if (minmod) {
                CHECKPOINT lastcp;
+               I32 lparen = *PL_reglastparen;
                minmod = 0;
                if (ln && regrepeat(scan, ln) < ln)
                    sayNO;
@@ -3740,6 +3745,7 @@ S_regmatch(pTHX_ regnode *prog)
                        if (c == (UV)c1 || c == (UV)c2)
                        {
                            TRYPAREN(paren, ln, PL_reginput);
+                           *PL_reglastparen = lparen;
                            REGCP_UNWIND(lastcp);
                        }
                    }
@@ -3747,6 +3753,7 @@ S_regmatch(pTHX_ regnode *prog)
                    else if (c1 == -1000)
                    {
                        TRYPAREN(paren, ln, PL_reginput);
+                       *PL_reglastparen = lparen;
                        REGCP_UNWIND(lastcp);
                    }
                    /* Couldn't or didn't -- move forward. */
@@ -3761,6 +3768,7 @@ S_regmatch(pTHX_ regnode *prog)
            }
            else {
                CHECKPOINT lastcp;
+               I32 lparen = *PL_reglastparen;
                n = regrepeat(scan, n);
                locinput = PL_reginput;
                if (ln < n && PL_regkind[(U8)OP(next)] == EOL &&
@@ -3791,6 +3799,7 @@ S_regmatch(pTHX_ regnode *prog)
                        if (c1 == -1000 || c == (UV)c1 || c == (UV)c2)
                            {
                                TRYPAREN(paren, n, PL_reginput);
+                               *PL_reglastparen = lparen;
                                REGCP_UNWIND(lastcp);
                            }
                        /* Couldn't or didn't -- back up. */
@@ -3814,6 +3823,7 @@ S_regmatch(pTHX_ regnode *prog)
                        if (c1 == -1000 || c == (UV)c1 || c == (UV)c2)
                            {
                                TRYPAREN(paren, n, PL_reginput);
+                               *PL_reglastparen = lparen;
                                REGCP_UNWIND(lastcp);
                            }
                        /* Couldn't or didn't -- back up. */
index d7e24f3..3daa676 100644 (file)
@@ -924,3 +924,19 @@ ab(?i)cd   abCd    y       -       -
 (??{}) x       y       -       -
 a(b)?? abc     y       <$1>    <>      # undef [perl #16773]
 (\d{1,3}\.){3,}        128.134.142.8   y       <$1>    <142.>  # [perl #18019]
+^.{3,4}(.+)\1\z        foobarbar       y       $1      bar     # 16 tests for [perl #23171]
+^(?:f|o|b){3,4}(.+)\1\z        foobarbar       y       $1      bar
+^.{3,4}((?:b|a|r)+)\1\z        foobarbar       y       $1      bar
+^(?:f|o|b){3,4}((?:b|a|r)+)\1\z        foobarbar       y       $1      bar
+^.{3,4}(.+?)\1\z       foobarbar       y       $1      bar
+^(?:f|o|b){3,4}(.+?)\1\z       foobarbar       y       $1      bar
+^.{3,4}((?:b|a|r)+?)\1\z       foobarbar       y       $1      bar
+^(?:f|o|b){3,4}((?:b|a|r)+?)\1\z       foobarbar       y       $1      bar
+^.{2,3}?(.+)\1\z       foobarbar       y       $1      bar
+^(?:f|o|b){2,3}?(.+)\1\z       foobarbar       y       $1      bar
+^.{2,3}?((?:b|a|r)+)\1\z       foobarbar       y       $1      bar
+^(?:f|o|b){2,3}?((?:b|a|r)+)\1\z       foobarbar       y       $1      bar
+^.{2,3}?(.+?)\1\z      foobarbar       y       $1      bar
+^(?:f|o|b){2,3}?(.+?)\1\z      foobarbar       y       $1      bar
+^.{2,3}?((?:b|a|r)+?)\1\z      foobarbar       y       $1      bar
+^(?:f|o|b){2,3}?((?:b|a|r)+?)\1\z      foobarbar       y       $1      bar