[Pcre-svn] [467] code/trunk: Fix study problem with JavaScri…

Página Inicial
Delete this message
Autor: Subversion repository
Data:  
Para: pcre-svn
Assunto: [Pcre-svn] [467] code/trunk: Fix study problem with JavaScript compatibility flag and back references.
Revision: 467
          http://vcs.pcre.org/viewvc?view=rev&revision=467
Author:   ph10
Date:     2009-10-19 12:43:18 +0100 (Mon, 19 Oct 2009)


Log Message:
-----------
Fix study problem with JavaScript compatibility flag and back references.

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


Modified: code/trunk/pcre_study.c
===================================================================
--- code/trunk/pcre_study.c    2009-10-19 11:42:08 UTC (rev 466)
+++ code/trunk/pcre_study.c    2009-10-19 11:43:18 UTC (rev 467)
@@ -314,18 +314,26 @@
     logic is that a recursion can only make sense if there is another
     alternation that stops the recursing. That will provide the minimum length
     (when no recursion happens). A backreference within the group that it is
-    referencing behaves in the same way. */
+    referencing behaves in the same way. 
+    
+    If PCRE_JAVASCRIPT_COMPAT is set, a backreference to an unset bracket
+    matches an empty string (by default it causes a matching failure), so in
+    that case we must set the minimum length to zero. */


     case OP_REF:
-    ce = cs = (uschar *)_pcre_find_bracket(startcode, utf8, GET2(cc, 1));
-    if (cs == NULL) return -2;
-    do ce += GET(ce, 1); while (*ce == OP_ALT);
-    if (cc > cs && cc < ce)
-      {
-      d = 0;
-      had_recurse = TRUE;
+    if ((options & PCRE_JAVASCRIPT_COMPAT) == 0)
+      {  
+      ce = cs = (uschar *)_pcre_find_bracket(startcode, utf8, GET2(cc, 1));
+      if (cs == NULL) return -2;
+      do ce += GET(ce, 1); while (*ce == OP_ALT);
+      if (cc > cs && cc < ce)
+        {
+        d = 0;
+        had_recurse = TRUE;
+        }
+      else d = find_minlength(cs, startcode, options);
       }
-    else d = find_minlength(cs, startcode, options);
+    else d = 0;    
     cc += 3;


     /* Handle repeated back references */


Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2009-10-19 11:42:08 UTC (rev 466)
+++ code/trunk/testdata/testinput2    2009-10-19 11:43:18 UTC (rev 467)
@@ -3160,4 +3160,13 @@
     ABX 
     BAXBAD  


+/(\3)(\1)(a)/<JS>
+    cat
+
+/(\3)(\1)(a)/SI<JS>
+    cat
+
+/(\3)(\1)(a)/SI
+    cat
+
 /-- End of testinput2 --/


Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2009-10-19 11:42:08 UTC (rev 466)
+++ code/trunk/testdata/testoutput2    2009-10-19 11:43:18 UTC (rev 467)
@@ -10431,4 +10431,36 @@
     BAXBAD  
 No match


+/(\3)(\1)(a)/<JS>
+    cat
+ 0: a
+ 1: 
+ 2: 
+ 3: a
+
+/(\3)(\1)(a)/SI<JS>
+Capturing subpattern count = 3
+Max back reference = 3
+Options:
+No first char
+Need char = 'a'
+Subject length lower bound = 1
+No set of starting bytes
+    cat
+ 0: a
+ 1: 
+ 2: 
+ 3: a
+
+/(\3)(\1)(a)/SI
+Capturing subpattern count = 3
+Max back reference = 3
+No options
+No first char
+Need char = 'a'
+Subject length lower bound = 3
+No set of starting bytes
+    cat
+No match
+
 /-- End of testinput2 --/