[Pcre-svn] [1739] code/trunk: Fix anchoring bug in condition…

Inizio della pagina
Delete this message
Autore: Subversion repository
Data:  
To: pcre-svn
Oggetto: [Pcre-svn] [1739] code/trunk: Fix anchoring bug in conditional subexpression.
Revision: 1739
          http://vcs.pcre.org/viewvc?view=rev&revision=1739
Author:   ph10
Date:     2018-09-02 18:05:38 +0100 (Sun, 02 Sep 2018)
Log Message:
-----------
Fix anchoring bug in conditional subexpression.


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


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2018-08-17 14:50:21 UTC (rev 1738)
+++ code/trunk/ChangeLog    2018-09-02 17:05:38 UTC (rev 1739)
@@ -32,7 +32,12 @@
 with only characters less than 0x100, the first class was incorrectly being   
 auto-possessified, causing incorrect match failures.


+6. If the only branch in a conditional subpattern was anchored, the whole
+subpattern was treated as anchored, when it should not have been, since the
+assumed empty second branch cannot be anchored. Demonstrated by test patterns
+such as /(?(1)^())b/ or /(?(?=^))b/.

+
Version 8.42 20-March-2018
--------------------------


Modified: code/trunk/pcre_compile.c
===================================================================
--- code/trunk/pcre_compile.c    2018-08-17 14:50:21 UTC (rev 1738)
+++ code/trunk/pcre_compile.c    2018-09-02 17:05:38 UTC (rev 1739)
@@ -8682,13 +8682,21 @@
      if (!is_anchored(scode, new_map, cd, atomcount)) return FALSE;
      }


- /* Positive forward assertions and conditions */
+ /* Positive forward assertion */

-   else if (op == OP_ASSERT || op == OP_COND)
+   else if (op == OP_ASSERT)
      {
      if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
      }


+   /* Condition; not anchored if no second branch */
+
+   else if (op == OP_COND)
+     {
+     if (scode[GET(scode,1)] != OP_ALT) return FALSE;
+     if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
+     }
+
    /* Atomic groups */


    else if (op == OP_ONCE || op == OP_ONCE_NC)


Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2018-08-17 14:50:21 UTC (rev 1738)
+++ code/trunk/testdata/testinput2    2018-09-02 17:05:38 UTC (rev 1739)
@@ -4257,4 +4257,7 @@
     ab
     aaab 


+/(?(?=^))b/
+    abc
+
 /-- End of testinput2 --/


Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2018-08-17 14:50:21 UTC (rev 1738)
+++ code/trunk/testdata/testoutput2    2018-09-02 17:05:38 UTC (rev 1739)
@@ -14721,4 +14721,8 @@
  0: ab
  1: a


+/(?(?=^))b/
+    abc
+ 0: b
+
 /-- End of testinput2 --/