summaryrefslogtreecommitdiff
path: root/t/re
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-03-30 09:59:47 +0200
committerYves Orton <demerphq@gmail.com>2022-04-08 12:29:21 +0800
commitdf12890b5e8c018402acec9b116df5182514fae1 (patch)
tree04412b033fdb9a1c363798494af120612c0c8c69 /t/re
parent8ec963d3eca5bc665f5b8d734b102c6a773bc02a (diff)
downloadperl-df12890b5e8c018402acec9b116df5182514fae1.tar.gz
regcomp.c: fix substring optimizer for ACCEPT inside of CURLY
ACCEPT essentially overrides quantifiers larger than 1. Eg, /(A){2}/ has a mincount of 2 and a maxcount of 2, and a minlen of 2 for "AA". But /(A(*ACCEPT)){2}/ should actually have a mincount of 1, and a minlen of 1 as it can match 'A'. In the regex engine proper this doesn't matter, we just do the right thing. But in the optimizer it matters. This patch sets the mincount to 1 in such cases whenever the contents contains an ACCEPT. Thanks for Hugo for asking the questions that lead to this patch.
Diffstat (limited to 't/re')
-rw-r--r--t/re/opt.t1
-rw-r--r--t/re/re_tests1
2 files changed, 2 insertions, 0 deletions
diff --git a/t/re/opt.t b/t/re/opt.t
index 3b110de99a..cee0601fcf 100644
--- a/t/re/opt.t
+++ b/t/re/opt.t
@@ -273,3 +273,4 @@ abc(*COMMIT)xyz 6 0+abc - -
abc(*ACCEPT)xyz 3 0+abc - -
# Must not have stclass=[x]
(*ACCEPT)xyz 0 - - -
+(a(*ACCEPT)){2} 1 0+a - -
diff --git a/t/re/re_tests b/t/re/re_tests
index 5455b90cbb..0d068d3205 100644
--- a/t/re/re_tests
+++ b/t/re/re_tests
@@ -2106,6 +2106,7 @@ AB\s+\x{100} AB \x{100}X y - -
/a?(*ACCEPT)b/ x y >$&< >< - # Test minlen for ACCEPT
/a?(*ACCEPT)b/ a y >$&< >a< - # Test minlen for ACCEPT
/a?(*ACCEPT)b/ b y >$&< >< - # Test minlen for ACCEPT
+/ (A (*ACCEPT) | BC){2} D{0,4}/x A y $1 A - # ACCEPT optimizer check
# Keep these lines at the end of the file
# pat string y/n/etc expr expected-expr skip-reason comment
# vim: softtabstop=0 noexpandtab