diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2010-06-15 17:20:55 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2010-06-15 17:20:55 +0000 |
commit | 0b7e881ffab59316d7fdef968feea28718f94d71 (patch) | |
tree | c4ab73a098506194a6b59219230b7c107b648876 | |
parent | 0cf340fbea16a8cc18935f2b02367a660f910474 (diff) | |
download | pcre-0b7e881ffab59316d7fdef968feea28718f94d71.tar.gz |
Fix forward reference in the presence of (?#( (open parens in comment).
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@544 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | pcre_compile.c | 39 | ||||
-rw-r--r-- | testdata/testinput11 | 5 | ||||
-rw-r--r-- | testdata/testoutput11 | 6 |
4 files changed, 42 insertions, 13 deletions
@@ -89,6 +89,11 @@ Version 8.10 03-Jun-2010 20. Added the /T option to pcretest so as to be able to run tests with non- standard character tables, thus making it possible to include the tests used for 19 above in the standard set of tests. + +21. A pattern such as (?&t)(?#()(?(DEFINE)(?<t>a)) which has a forward + reference to a subpattern the other side of a comment that contains an + opening parenthesis caused either an internal compiling error, or a + reference to the wrong subpattern. Version 8.02 19-Mar-2010 diff --git a/pcre_compile.c b/pcre_compile.c index 3a23768..eab5991 100644 --- a/pcre_compile.c +++ b/pcre_compile.c @@ -1129,25 +1129,39 @@ dealing with. The very first call may not start with a parenthesis. */ if (ptr[0] == CHAR_LEFT_PARENTHESIS) { - if (ptr[1] == CHAR_QUESTION_MARK && - ptr[2] == CHAR_VERTICAL_LINE) - { - ptr += 3; - dup_parens = TRUE; - } + /* Handle specials such as (*SKIP) or (*UTF8) etc. */ + + if (ptr[1] == CHAR_ASTERISK) ptr += 2; + + /* Handle a normal, unnamed capturing parenthesis. */ - /* Handle a normal, unnamed capturing parenthesis */ - - else if (ptr[1] != CHAR_QUESTION_MARK && ptr[1] != CHAR_ASTERISK) + else if (ptr[1] != CHAR_QUESTION_MARK) { *count += 1; if (name == NULL && *count == lorn) return *count; ptr++; } + /* All cases now have (? at the start. Remember when we are in a group + where the parenthesis numbers are duplicated. */ + + else if (ptr[2] == CHAR_VERTICAL_LINE) + { + ptr += 3; + dup_parens = TRUE; + } + + /* Handle comments; all characters are allowed until a ket is reached. */ + + else if (ptr[2] == CHAR_NUMBER_SIGN) + { + for (ptr += 3; *ptr != 0; ptr++) if (*ptr == CHAR_RIGHT_PARENTHESIS) break; + goto FAIL_EXIT; + } + /* Handle a condition. If it is an assertion, just carry on so that it is processed as normal. If not, skip to the closing parenthesis of the - condition (there can't be any nested parens. */ + condition (there can't be any nested parens). */ else if (ptr[2] == CHAR_LEFT_PARENTHESIS) { @@ -1159,7 +1173,7 @@ if (ptr[0] == CHAR_LEFT_PARENTHESIS) } } - /* We have either (? or (* and not a condition */ + /* Start with (? but not a condition. */ else { @@ -1281,8 +1295,7 @@ for (; *ptr != 0; ptr++) else if (*ptr == CHAR_RIGHT_PARENTHESIS) { if (dup_parens && *count < hwm_count) *count = hwm_count; - *ptrptr = ptr; - return -1; + goto FAIL_EXIT; } else if (*ptr == CHAR_VERTICAL_LINE && dup_parens) diff --git a/testdata/testinput11 b/testdata/testinput11 index c074176..795e1be 100644 --- a/testdata/testinput11 +++ b/testdata/testinput11 @@ -478,4 +478,9 @@ however, we need the complication for Perl. ---/ /(\w+)b(*COMMIT)\w{2}/ abbb +/--- Check opening parens in comment when seeking forward reference. ---/ + +/(?&t)(?#()(?(DEFINE)(?<t>a))/ + bac + /-- End of testinput11 --/ diff --git a/testdata/testoutput11 b/testdata/testoutput11 index 8b0f111..6270d5b 100644 --- a/testdata/testoutput11 +++ b/testdata/testoutput11 @@ -936,4 +936,10 @@ No match abbb No match +/--- Check opening parens in comment when seeking forward reference. ---/ + +/(?&t)(?#()(?(DEFINE)(?<t>a))/ + bac + 0: a + /-- End of testinput11 --/ |