From 1d44822484f3a9cf0dbe2407b7aec7c80a4afaf6 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Tue, 9 Jun 2015 17:41:45 +0000 Subject: [PATCH] Fix empty string matching bug. --- ChangeLog | 4 ++++ src/pcre2_compile.c | 4 ++-- testdata/testinput2 | 2 ++ testdata/testoutput2 | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 544ca76..37b565d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -151,6 +151,10 @@ overflows. 38. The table entry for \l in EBCDIC environments was incorrect, leading to its being treated as a literal 'l' instead of causing an error. +39. If a non-capturing group containing a conditional group that could match +an empty string was repeated, it was not identified as matching an empty string +itself. For example: /^(?:(?(1)x|)+)+$()/. + Version 10.10 06-March-2015 --------------------------- diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index 7acd1d5..80c2d08 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -1238,7 +1238,7 @@ for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE); PCRE2_SPTR ccode; c = *code; - + /* Skip over forward assertions; the other assertions are skipped by first_significant_code() with a TRUE final argument. */ @@ -1338,7 +1338,7 @@ for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE); if (c == OP_BRA || c == OP_BRAPOS || c == OP_CBRA || c == OP_CBRAPOS || c == OP_ONCE || c == OP_ONCE_NC || - c == OP_COND) + c == OP_COND || c == OP_SCOND) { BOOL empty_branch; if (GET(code, 1) == 0) return TRUE; /* Hit unclosed bracket */ diff --git a/testdata/testinput2 b/testdata/testinput2 index 70cfc06..e0e149f 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -4325,4 +4325,6 @@ a random value. /Ix /(?<=|(\,\$(?73591620449005828816)\xa8.{7}){6}\x09)/ +/^(?:(?(1)x|)+)+$()/B + # End of testinput2 diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 7de0b8a..b628466 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -14452,4 +14452,22 @@ Failed: error 162 at offset 4: subpattern name expected /(?<=|(\,\$(?73591620449005828816)\xa8.{7}){6}\x09)/ Failed: error 161 at offset 32: number is too big +/^(?:(?(1)x|)+)+$()/B +------------------------------------------------------------------ + Bra + ^ + SBra + SCond + 1 Cond ref + x + Alt + KetRmax + KetRmax + $ + CBra 1 + Ket + Ket + End +------------------------------------------------------------------ + # End of testinput2