[Pcre-svn] [750] code/trunk: Fix problem with possessively r…

Startseite
Nachricht löschen
Autor: Subversion repository
Datum:  
To: pcre-svn
Betreff: [Pcre-svn] [750] code/trunk: Fix problem with possessively repeated groups with minima greater than one .
Revision: 750
          http://vcs.pcre.org/viewvc?view=rev&revision=750
Author:   ph10
Date:     2011-11-18 11:07:14 +0000 (Fri, 18 Nov 2011)


Log Message:
-----------
Fix problem with possessively repeated groups with minima greater than one.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_compile.c
    code/trunk/testdata/testinput1
    code/trunk/testdata/testoutput1


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2011-11-18 10:36:45 UTC (rev 749)
+++ code/trunk/ChangeLog    2011-11-18 11:07:14 UTC (rev 750)
@@ -36,6 +36,11 @@


 8.  A possessively repeated conditional subpattern such as (?(?=c)c|d)++ was
     being incorrectly compiled and would have given unpredicatble results. 
+    
+9.  A possessively repeated subpattern with minimum repeat count greater than 
+    one behaved incorrectly. For example, (A){2,}+ behaved as if it was
+    (A)(A)++ which meant that, after a subsequent mismatch, backtracking into 
+    the first (A) could occur when it should not. 



Version 8.20 21-Oct-2011

Modified: code/trunk/pcre_compile.c
===================================================================
--- code/trunk/pcre_compile.c    2011-11-18 10:36:45 UTC (rev 749)
+++ code/trunk/pcre_compile.c    2011-11-18 11:07:14 UTC (rev 750)
@@ -4994,9 +4994,13 @@
       KETRPOS. (It turns out to be convenient at runtime to detect this kind of
       subpattern at both the start and at the end.) The use of special opcodes
       makes it possible to reduce greatly the stack usage in pcre_exec(). If
-      the group is preceded by OP_BRAZERO, convert this to OP_BRAPOSZERO. Then
-      cancel the possessive flag so that the default action below, of wrapping
-      everything inside atomic brackets, does not happen. */
+      the group is preceded by OP_BRAZERO, convert this to OP_BRAPOSZERO. 
+       
+      Then, if the minimum number of matches is 1 or 0, cancel the possessive
+      flag so that the default action below, of wrapping everything inside
+      atomic brackets, does not happen. When the minimum is greater than 1,
+      there will be earlier copies of the group, and so we still have to wrap 
+      the whole thing. */


       else
         {
@@ -5068,10 +5072,10 @@
               }


             /* If the minimum is zero, mark it as possessive, then unset the 
-            possessive flag. */
+            possessive flag when the minimum is 0 or 1. */


             if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;
-            possessive_quantifier = FALSE;
+            if (repeat_min < 2) possessive_quantifier = FALSE;
             }


           /* Non-possessive quantifier */
@@ -5103,9 +5107,9 @@
     notation is just syntactic sugar, taken from Sun's Java package, but the
     special opcodes can optimize it.


-    Possessively repeated subpatterns have already been handled in the code
-    just above, so possessive_quantifier is always FALSE for them at this
-    stage.
+    Some (but not all) possessively repeated subpatterns have already been
+    completely handled in the code just above. For them, possessive_quantifier
+    is always FALSE at this stage.


     Note that the repeated item starts at tempcode, not at previous, which
     might be the first part of a string whose (former) last char we repeated.


Modified: code/trunk/testdata/testinput1
===================================================================
--- code/trunk/testdata/testinput1    2011-11-18 10:36:45 UTC (rev 749)
+++ code/trunk/testdata/testinput1    2011-11-18 11:07:14 UTC (rev 750)
@@ -4291,4 +4291,18 @@
 /(?(?=c)c|d)*+Y/
     XcccddYX


+/^(a{2,3}){2,}+a/
+    aaaaaaa
+    ** Failers
+    aaaaaa
+    aaaaaaaaa 
+
+/^(a{2,3})++a/
+    ** Failers
+    aaaaaa
+
+/^(a{2,3})*+a/
+    ** Failers
+    aaaaaa
+
 /-- End of testinput1 --/


Modified: code/trunk/testdata/testoutput1
===================================================================
--- code/trunk/testdata/testoutput1    2011-11-18 10:36:45 UTC (rev 749)
+++ code/trunk/testdata/testoutput1    2011-11-18 11:07:14 UTC (rev 750)
@@ -7012,4 +7012,27 @@
     XcccddYX
  0: cccddY


+/^(a{2,3}){2,}+a/
+    aaaaaaa
+ 0: aaaaaaa
+ 1: aaa
+    ** Failers
+No match
+    aaaaaa
+No match
+    aaaaaaaaa 
+No match
+
+/^(a{2,3})++a/
+    ** Failers
+No match
+    aaaaaa
+No match
+
+/^(a{2,3})*+a/
+    ** Failers
+No match
+    aaaaaa
+No match
+
 /-- End of testinput1 --/