[Pcre-svn] [882] code/trunk: Fix nested *MARK bug (nothing s…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [882] code/trunk: Fix nested *MARK bug (nothing shown for /(?=(*:x))((*:y) q|)/ etc.)
Revision: 882
          http://vcs.pcre.org/viewvc?view=rev&revision=882
Author:   ph10
Date:     2012-01-15 18:45:27 +0000 (Sun, 15 Jan 2012)


Log Message:
-----------
Fix nested *MARK bug (nothing shown for /(?=(*:x))((*:y)q|)/ etc.)

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_exec.c
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput2


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2012-01-15 18:07:05 UTC (rev 881)
+++ code/trunk/ChangeLog    2012-01-15 18:45:27 UTC (rev 882)
@@ -38,7 +38,13 @@


10. Get rid of a number of -Wunused-but-set-variable warnings.

+11. The pattern /(?=(*:x))(q|)/ matches an empty string, and returns the mark 
+    "x". The similar pattern /(?=(*:x))((*:y)q|)/ did not return a mark at all. 
+    Oddly, Perl behaves the same way. PCRE has been fixed so that this pattern 
+    also returns the mark "x". This bug applied to capturing parentheses, 
+    non-capturing parentheses, and atomic parentheses. 


+
Version 8.21 12-Dec-2011
------------------------


Modified: code/trunk/pcre_exec.c
===================================================================
--- code/trunk/pcre_exec.c    2012-01-15 18:07:05 UTC (rev 881)
+++ code/trunk/pcre_exec.c    2012-01-15 18:45:27 UTC (rev 882)
@@ -626,6 +626,7 @@
 #define condassert    condition
 #define matched_once  prev_is_word
 #define foc           number
+#define save_mark     data


 /* These statements are here to stop the compiler complaining about unitialized
 variables. */
@@ -818,6 +819,7 @@
     case OP_ONCE_NC:
     prev = ecode;
     saved_eptr = eptr;
+    save_mark = md->mark; 
     do
       {
       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);
@@ -836,6 +838,7 @@


       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode += GET(ecode,1);
+      md->mark = save_mark; 
       }
     while (*ecode == OP_ALT);


@@ -915,6 +918,7 @@
       save_offset2 = md->offset_vector[offset+1];
       save_offset3 = md->offset_vector[md->offset_end - number];
       save_capture_last = md->capture_last;
+      save_mark = md->mark; 


       DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
       md->offset_vector[md->offset_end - number] =
@@ -951,6 +955,7 @@
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);
         md->capture_last = save_capture_last;
         ecode += GET(ecode, 1);
+        md->mark = save_mark;
         if (*ecode != OP_ALT) break;
         }


@@ -1016,9 +1021,10 @@

       /* In all other cases, we have to make another call to match(). */


+      save_mark = md->mark;
       RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb,
         RM2);
-
+         
       /* See comment in the code for capturing groups above about handling
       THEN. */


@@ -1045,6 +1051,7 @@
         RRETURN(rrc);
         }
       ecode += GET(ecode, 1);
+      md->mark = save_mark; 
       if (*ecode != OP_ALT) break;
       }



Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2012-01-15 18:07:05 UTC (rev 881)
+++ code/trunk/testdata/testinput2    2012-01-15 18:45:27 UTC (rev 882)
@@ -3580,5 +3580,19 @@


 /^a(*:X)bcde/K
    abc\P
+   
+/-- These are here because Perl doesn't return a mark, except for the first --/


+/(?=(*:x))(q|)/K+
+    abc
+
+/(?=(*:x))((*:y)q|)/K+
+    abc
+
+/(?=(*:x))(?:(*:y)q|)/K+
+    abc
+
+/(?=(*:x))(?>(*:y)q|)/K+
+    abc
+
 /-- End of testinput2 --/


Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2012-01-15 18:07:05 UTC (rev 881)
+++ code/trunk/testdata/testoutput2    2012-01-15 18:45:27 UTC (rev 882)
@@ -11970,5 +11970,33 @@
 /^a(*:X)bcde/K
    abc\P
 Partial match, mark=X: abc
+   
+/-- These are here because Perl doesn't return a mark, except for the first --/


+/(?=(*:x))(q|)/K+
+    abc
+ 0: 
+ 0+ abc
+ 1: 
+MK: x
+
+/(?=(*:x))((*:y)q|)/K+
+    abc
+ 0: 
+ 0+ abc
+ 1: 
+MK: x
+
+/(?=(*:x))(?:(*:y)q|)/K+
+    abc
+ 0: 
+ 0+ abc
+MK: x
+
+/(?=(*:x))(?>(*:y)q|)/K+
+    abc
+ 0: 
+ 0+ abc
+MK: x
+
 /-- End of testinput2 --/