[Pcre-svn] [976] code/trunk: Fix capture problem with repeat…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [976] code/trunk: Fix capture problem with repeated, empty-string-matching groups.
Revision: 976
          http://vcs.pcre.org/viewvc?view=rev&revision=976
Author:   ph10
Date:     2012-06-16 18:53:17 +0100 (Sat, 16 Jun 2012)


Log Message:
-----------
Fix capture problem with repeated, empty-string-matching groups.

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


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2012-06-02 11:03:06 UTC (rev 975)
+++ code/trunk/ChangeLog    2012-06-16 17:53:17 UTC (rev 976)
@@ -126,7 +126,11 @@


35. Improve JIT code generation for greedy plus quantifier.

+36. When /((?:a?)*)*c/ or /((?>a?)*)*c/ was matched against "aac", it set group
+    1 to "aa" instead of to an empty string. The bug affected repeated groups
+    that could potentially match an empty string.


+
Version 8.30 04-February-2012
-----------------------------


Modified: code/trunk/pcre_exec.c
===================================================================
--- code/trunk/pcre_exec.c    2012-06-02 11:03:06 UTC (rev 975)
+++ code/trunk/pcre_exec.c    2012-06-16 17:53:17 UTC (rev 976)
@@ -37,7 +37,6 @@
 -----------------------------------------------------------------------------
 */


-
 /* This module contains pcre_exec(), the externally visible function that does
 pattern matching using an NFA algorithm, trying to mimic Perl as closely as
 possible. There are also some static supporting functions. */
@@ -907,7 +906,6 @@
       }
     else  /* OP_KETRMAX */
       {
-      md->match_function_type = MATCH_CBEGROUP;
       RMATCH(eptr, prev, offset_top, md, eptrb, RM66);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode += 1 + LINK_SIZE;
@@ -1036,7 +1034,8 @@


     for (;;)
       {
-      if (op >= OP_SBRA || op == OP_ONCE) md->match_function_type = MATCH_CBEGROUP;
+      if (op >= OP_SBRA || op == OP_ONCE)
+        md->match_function_type = MATCH_CBEGROUP;


       /* If this is not a possibly empty group, and there are no (*THEN)s in
       the pattern, and this is the final alternative, optimize as described
@@ -2009,7 +2008,6 @@
         }
       if (*prev >= OP_SBRA)    /* Could match an empty string */
         {
-        md->match_function_type = MATCH_CBEGROUP;
         RMATCH(eptr, prev, offset_top, md, eptrb, RM50);
         RRETURN(rrc);
         }
@@ -2018,7 +2016,6 @@
       }
     else  /* OP_KETRMAX */
       {
-      if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
       RMATCH(eptr, prev, offset_top, md, eptrb, RM13);
       if (rrc == MATCH_ONCE && md->once_target == prev) rrc = MATCH_NOMATCH;
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
@@ -3431,7 +3428,7 @@
     maximizing, find the maximum number of characters and work backwards. */


     DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
-      max, eptr));
+      max, (char *)eptr));


     if (op >= OP_STARI)  /* Caseless */
       {
@@ -3700,7 +3697,7 @@
     characters and work backwards. */


     DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max,
-      max, eptr));
+      max, (char *)eptr));


     if (op >= OP_NOTSTARI)     /* Caseless */
       {


Modified: code/trunk/testdata/testinput1
===================================================================
--- code/trunk/testdata/testinput1    2012-06-02 11:03:06 UTC (rev 975)
+++ code/trunk/testdata/testinput1    2012-06-16 17:53:17 UTC (rev 976)
@@ -5256,4 +5256,10 @@
 /(?!a(*COMMIT)b)ac|cd/
     ac


+/((?:a?)*)*c/
+ aac
+
+/((?>a?)*)*c/
+ aac
+
/-- End of testinput1 --/

Modified: code/trunk/testdata/testoutput1
===================================================================
--- code/trunk/testdata/testoutput1    2012-06-02 11:03:06 UTC (rev 975)
+++ code/trunk/testdata/testoutput1    2012-06-16 17:53:17 UTC (rev 976)
@@ -8723,4 +8723,14 @@
     ac
  0: ac


+/((?:a?)*)*c/
+ aac
+ 0: aac
+ 1:
+
+/((?>a?)*)*c/
+ aac
+ 0: aac
+ 1:
+
/-- End of testinput1 --/