[Pcre-svn] [544] code/trunk: Fix forward reference in the pr…

Página Inicial
Delete this message
Autor: Subversion repository
Data:  
Para: pcre-svn
Assunto: [Pcre-svn] [544] code/trunk: Fix forward reference in the presence of (?#( ( open parens in comment).
Revision: 544
          http://vcs.pcre.org/viewvc?view=rev&revision=544
Author:   ph10
Date:     2010-06-15 18:20:55 +0100 (Tue, 15 Jun 2010)


Log Message:
-----------
Fix forward reference in the presence of (?#( (open parens in comment).

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_compile.c
    code/trunk/testdata/testinput11
    code/trunk/testdata/testoutput11


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2010-06-15 16:33:29 UTC (rev 543)
+++ code/trunk/ChangeLog    2010-06-15 17:20:55 UTC (rev 544)
@@ -89,6 +89,11 @@
 20. Added the /T option to pcretest so as to be able to run tests with non-
     standard character tables, thus making it possible to include the tests
     used for 19 above in the standard set of tests.  
+    
+21. A pattern such as (?&t)(?#()(?(DEFINE)(?<t>a)) which has a forward 
+    reference to a subpattern the other side of a comment that contains an 
+    opening parenthesis caused either an internal compiling error, or a 
+    reference to the wrong subpattern.



Version 8.02 19-Mar-2010

Modified: code/trunk/pcre_compile.c
===================================================================
--- code/trunk/pcre_compile.c    2010-06-15 16:33:29 UTC (rev 543)
+++ code/trunk/pcre_compile.c    2010-06-15 17:20:55 UTC (rev 544)
@@ -1129,25 +1129,39 @@


 if (ptr[0] == CHAR_LEFT_PARENTHESIS)
   {
-  if (ptr[1] == CHAR_QUESTION_MARK &&
-      ptr[2] == CHAR_VERTICAL_LINE)
-    {
-    ptr += 3;
-    dup_parens = TRUE;
-    }
+  /* Handle specials such as (*SKIP) or (*UTF8) etc. */
+  
+  if (ptr[1] == CHAR_ASTERISK) ptr += 2;
+ 
+  /* Handle a normal, unnamed capturing parenthesis. */


-  /* Handle a normal, unnamed capturing parenthesis */
-
-  else if (ptr[1] != CHAR_QUESTION_MARK && ptr[1] != CHAR_ASTERISK)
+  else if (ptr[1] != CHAR_QUESTION_MARK)
     {
     *count += 1;
     if (name == NULL && *count == lorn) return *count;
     ptr++;
     }


+  /* All cases now have (? at the start. Remember when we are in a group
+  where the parenthesis numbers are duplicated. */
+
+  else if (ptr[2] == CHAR_VERTICAL_LINE)
+    {
+    ptr += 3;
+    dup_parens = TRUE;
+    }
+    
+  /* Handle comments; all characters are allowed until a ket is reached. */
+
+  else if (ptr[2] == CHAR_NUMBER_SIGN)
+    {
+    for (ptr += 3; *ptr != 0; ptr++) if (*ptr == CHAR_RIGHT_PARENTHESIS) break;
+    goto FAIL_EXIT;
+    }  
+
   /* Handle a condition. If it is an assertion, just carry on so that it
   is processed as normal. If not, skip to the closing parenthesis of the
-  condition (there can't be any nested parens. */
+  condition (there can't be any nested parens). */


   else if (ptr[2] == CHAR_LEFT_PARENTHESIS)
     {
@@ -1159,7 +1173,7 @@
       }
     }


- /* We have either (? or (* and not a condition */
+ /* Start with (? but not a condition. */

   else
     {
@@ -1281,8 +1295,7 @@
   else if (*ptr == CHAR_RIGHT_PARENTHESIS)
     {
     if (dup_parens && *count < hwm_count) *count = hwm_count;
-    *ptrptr = ptr;
-    return -1;
+    goto FAIL_EXIT; 
     }


else if (*ptr == CHAR_VERTICAL_LINE && dup_parens)

Modified: code/trunk/testdata/testinput11
===================================================================
--- code/trunk/testdata/testinput11    2010-06-15 16:33:29 UTC (rev 543)
+++ code/trunk/testdata/testinput11    2010-06-15 17:20:55 UTC (rev 544)
@@ -478,4 +478,9 @@
 /(\w+)b(*COMMIT)\w{2}/
     abbb


+/--- Check opening parens in comment when seeking forward reference. ---/ 
+
+/(?&t)(?#()(?(DEFINE)(?<t>a))/
+    bac
+
 /-- End of testinput11 --/


Modified: code/trunk/testdata/testoutput11
===================================================================
--- code/trunk/testdata/testoutput11    2010-06-15 16:33:29 UTC (rev 543)
+++ code/trunk/testdata/testoutput11    2010-06-15 17:20:55 UTC (rev 544)
@@ -936,4 +936,10 @@
     abbb
 No match


+/--- Check opening parens in comment when seeking forward reference. ---/ 
+
+/(?&t)(?#()(?(DEFINE)(?<t>a))/
+    bac
+ 0: a
+
 /-- End of testinput11 --/