Re: [perl #23030] Error in negative lookahead with alternations
Hugo van der Sanden [Thu, 7 Aug 2003 02:44:23 +0000 (03:44 +0100)]
Message-Id: <200308070144.h771iN906446@zen.crypt.org>

p4raw-id: //depot/perl@20538

regexec.c
t/op/re_tests

index df96924..1127933 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -87,6 +87,7 @@
 #define RF_warned      2               /* warned about big count? */
 #define RF_evaled      4               /* Did an EVAL with setting? */
 #define RF_utf8                8               /* String contains multibyte chars? */
+#define RF_false       16              /* odd number of nested negatives */
 
 #define UTF ((PL_reg_flags & RF_utf8) != 0)
 
@@ -3204,7 +3205,10 @@ S_regmatch(pTHX_ regnode *prog)
                                      "%*s  already tried at this position...\n",
                                      REPORT_CODE_OFF+PL_regindent*2, "")
                        );
-                       sayNO_SILENT;
+                       if (PL_reg_flags & RF_false)
+                           sayYES;
+                       else
+                           sayNO_SILENT;
                    }
                    PL_reg_poscache[o] |= (1<<b);
                }
@@ -3854,6 +3858,7 @@ S_regmatch(pTHX_ regnode *prog)
            }
            else
                PL_reginput = locinput;
+           PL_reg_flags ^= RF_false;
            goto do_ifmatch;
        case IFMATCH:
            n = 1;
@@ -3869,6 +3874,8 @@ S_regmatch(pTHX_ regnode *prog)
          do_ifmatch:
            inner = NEXTOPER(NEXTOPER(scan));
            if (regmatch(inner) != n) {
+               if (n == 0)
+                   PL_reg_flags ^= RF_false;
              say_no:
                if (logical) {
                    logical = 0;
@@ -3878,6 +3885,8 @@ S_regmatch(pTHX_ regnode *prog)
                else
                    sayNO;
            }
+           if (n == 0)
+               PL_reg_flags ^= RF_false;
          say_yes:
            if (logical) {
                logical = 0;
index 3daa676..b794aea 100644 (file)
@@ -940,3 +940,4 @@ a(b)??      abc     y       <$1>    <>      # undef [perl #16773]
 ^(?: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
+.*a(?!(b|cd)*e).*f     ......abef      n       -       -       # [perl #23030]