summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2009-10-19 11:43:18 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2009-10-19 11:43:18 +0000
commit351e183b094222a739b28c02779cfe400d989c1d (patch)
treeaf4686f4e3a8ebb61e54e56b37721e8588728149
parent44108c7b2d582141ec946a276dcd8cdf2eec516a (diff)
downloadpcre-351e183b094222a739b28c02779cfe400d989c1d.tar.gz
Fix study problem with JavaScript compatibility flag and back references.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@467 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--pcre_study.c26
-rw-r--r--testdata/testinput29
-rw-r--r--testdata/testoutput232
3 files changed, 58 insertions, 9 deletions
diff --git a/pcre_study.c b/pcre_study.c
index 8e1cc6e..91b44c0 100644
--- a/pcre_study.c
+++ b/pcre_study.c
@@ -314,18 +314,26 @@ for (;;)
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 */
diff --git a/testdata/testinput2 b/testdata/testinput2
index 57188e4..3319bb7 100644
--- a/testdata/testinput2
+++ b/testdata/testinput2
@@ -3160,4 +3160,13 @@ a random value. /Ix
ABX
BAXBAD
+/(\3)(\1)(a)/<JS>
+ cat
+
+/(\3)(\1)(a)/SI<JS>
+ cat
+
+/(\3)(\1)(a)/SI
+ cat
+
/-- End of testinput2 --/
diff --git a/testdata/testoutput2 b/testdata/testoutput2
index 2a90af4..30ea63b 100644
--- a/testdata/testoutput2
+++ b/testdata/testoutput2
@@ -10431,4 +10431,36 @@ No match
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 --/