[Pcre-svn] [848] code/trunk: Fix bug in /xx implementation.

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [848] code/trunk: Fix bug in /xx implementation.
Revision: 848
          http://www.exim.org/viewvc/pcre2?view=rev&revision=848
Author:   ph10
Date:     2017-07-25 16:27:30 +0100 (Tue, 25 Jul 2017)
Log Message:
-----------
Fix bug in /xx implementation.


Modified Paths:
--------------
    code/trunk/src/pcre2_compile.c
    code/trunk/testdata/testinput1
    code/trunk/testdata/testoutput1


Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c    2017-07-24 04:05:38 UTC (rev 847)
+++ code/trunk/src/pcre2_compile.c    2017-07-25 15:27:30 UTC (rev 848)
@@ -3535,8 +3535,12 @@
             /* If x appears twice it sets the extended extended option. */


             case CHAR_x:
-            *optset |= ((*optset & PCRE2_EXTENDED) != 0)?
-              PCRE2_EXTENDED_MORE : PCRE2_EXTENDED;
+            *optset |= PCRE2_EXTENDED;
+            if (ptr < ptrend && *ptr == CHAR_x)
+              {
+              *optset |= PCRE2_EXTENDED_MORE;
+              ptr++;
+              }
             break;


             default:
@@ -3545,12 +3549,17 @@
             goto FAILED;
             }
           }
-        options = (options | set) & (~unset);


-        /* Unsetting extended should also get rid of extended-more. */
+        /* If we are setting extended without extended-more, ensure that any
+        existing extended-more gets unset. Also, unsetting extended must also
+        unset extended-more. */


-        if ((options & PCRE2_EXTENDED) == 0) options &= ~PCRE2_EXTENDED_MORE;
+        if ((set & (PCRE2_EXTENDED|PCRE2_EXTENDED_MORE)) == PCRE2_EXTENDED ||
+            (unset & PCRE2_EXTENDED) != 0)
+          unset |= PCRE2_EXTENDED_MORE;


+        options = (options | set) & (~unset);
+
         /* If the options ended with ')' this is not the start of a nested
         group with option changes, so the options change at this level.
         In this case, if the previous level set up a nest block, discard the


Modified: code/trunk/testdata/testinput1
===================================================================
--- code/trunk/testdata/testinput1    2017-07-24 04:05:38 UTC (rev 847)
+++ code/trunk/testdata/testinput1    2017-07-25 15:27:30 UTC (rev 848)
@@ -6146,4 +6146,16 @@


# --------------------------------------------------------------------------

+/<(?x:[a b])>/xx
+    < >
+
+/<(?:[a b])>/xx
+    < >
+
+/<(?xxx:[a b])>/
+    < >
+    
+/<(?-x:[a b])>/xx
+    < >
+
 # End of testinput1 


Modified: code/trunk/testdata/testoutput1
===================================================================
--- code/trunk/testdata/testoutput1    2017-07-24 04:05:38 UTC (rev 847)
+++ code/trunk/testdata/testoutput1    2017-07-25 15:27:30 UTC (rev 848)
@@ -9739,4 +9739,20 @@


# --------------------------------------------------------------------------

+/<(?x:[a b])>/xx
+    < >
+ 0: < >
+
+/<(?:[a b])>/xx
+    < >
+No match
+
+/<(?xxx:[a b])>/
+    < >
+No match
+    
+/<(?-x:[a b])>/xx
+    < >
+ 0: < >
+
 # End of testinput1