From 623b497851a4659f15f749569ef320b1b9def5f0 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Fri, 10 Oct 2014 16:16:44 +0000 Subject: [PATCH] Fix "first code unit" bug. --- src/pcre2_compile.c | 17 +++++++++-------- testdata/testinput1 | 4 ++++ testdata/testinput2 | 8 ++++++++ testdata/testoutput1 | 7 +++++++ testdata/testoutput2 | 22 ++++++++++++++++++++++ 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index 4876038..2af6e02 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -6219,7 +6219,7 @@ for (;; ptr++) than one can replicate it as reqcu if necessary. If the subpattern has no firstcu, set "none" for the whole branch. In both cases, a zero repeat forces firstcu to "none". */ - + if (firstcuflags == REQ_UNSET && subfirstcuflags != REQ_UNSET) { if (subfirstcuflags >= 0) @@ -6750,15 +6750,16 @@ for (;;) we have to abandon the firstcu for the regex, but if there was previously no reqcu, it takes on the value of the old firstcu. */ - if (firstcuflags >= 0 && - (firstcuflags != branchfirstcuflags || - firstcu != branchfirstcu)) + if (firstcuflags != branchfirstcuflags || firstcu != branchfirstcu) { - if (reqcuflags < 0) + if (firstcuflags >= 0) { - reqcu = firstcu; - reqcuflags = firstcuflags; - } + if (reqcuflags < 0) + { + reqcu = firstcu; + reqcuflags = firstcuflags; + } + } firstcuflags = REQ_NONE; } diff --git a/testdata/testinput1 b/testdata/testinput1 index dfed98f..2aea25d 100644 --- a/testdata/testinput1 +++ b/testdata/testinput1 @@ -5698,4 +5698,8 @@ name)/mark A8B A9B +/(|ab)*?d/ + abd + xyd + # End of testinput1 diff --git a/testdata/testinput2 b/testdata/testinput2 index 3522a16..4af89b2 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -3995,4 +3995,12 @@ a random value. /Ix /abcd/I,no_start_optimize +/(|ab)*?d/I + abd + xyd + +/(|ab)*?d/I,no_start_optimize + abd + xyd + # End of testinput2 diff --git a/testdata/testoutput1 b/testdata/testoutput1 index 2059825..8240536 100644 --- a/testdata/testoutput1 +++ b/testdata/testoutput1 @@ -9396,4 +9396,11 @@ No match A9B 0: A9B +/(|ab)*?d/ + abd + 0: abd + 1: ab + xyd + 0: d + # End of testinput1 diff --git a/testdata/testoutput2 b/testdata/testoutput2 index d1b74dc..e086358 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -13554,4 +13554,26 @@ Capturing subpattern count = 0 Options: no_start_optimize Subject length lower bound = 0 +/(|ab)*?d/I +Capturing subpattern count = 1 +Starting code units: a d +Last code unit = 'd' +Subject length lower bound = 1 + abd + 0: abd + 1: ab + xyd + 0: d + +/(|ab)*?d/I,no_start_optimize +Capturing subpattern count = 1 +Options: no_start_optimize +Last code unit = 'd' +Subject length lower bound = 0 + abd + 0: abd + 1: ab + xyd + 0: d + # End of testinput2