summaryrefslogtreecommitdiff
path: root/pcre_study.c
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 /pcre_study.c
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
Diffstat (limited to 'pcre_study.c')
-rw-r--r--pcre_study.c26
1 files changed, 17 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 */