summaryrefslogtreecommitdiff
path: root/t/lib/croak/regcomp
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2020-09-14 16:00:28 +1000
committerSteve Hay <steve.m.hay@googlemail.com>2021-01-06 17:40:16 +0000
commit536520b4a24d012a8aa0690f044f651300258171 (patch)
treecd3879de39c809692ce490c1c169a2722786f253 /t/lib/croak/regcomp
parent7925f8dfc09ddebcbfa214fdcd854c52090586f9 (diff)
downloadperl-536520b4a24d012a8aa0690f044f651300258171.tar.gz
don't croak when the \K follows the lookaround assertion
this also simplifies the flagging for these assertions, since this error is now the only thing using in_lookhead and in_lookbehind they can be combined into a single in_lookaround. Rather than conditional increment/decrement as we recurse into S_reg I simply save the value of in_lookaround and restore it before returning. Some unsuccessful or restart paths don't do the restore, but they either result in a croak(), or a restart which reinitialises in_lookaround anyway. Also added tests to ensure that all the different zero-width assertions with content trigger the error. (cherry picked from commit 80f44cf4982e395989f886220e05dd2071bb205a)
Diffstat (limited to 't/lib/croak/regcomp')
-rw-r--r--t/lib/croak/regcomp43
1 files changed, 41 insertions, 2 deletions
diff --git a/t/lib/croak/regcomp b/t/lib/croak/regcomp
index 476b239fa7..74e70ed363 100644
--- a/t/lib/croak/regcomp
+++ b/t/lib/croak/regcomp
@@ -77,15 +77,54 @@ EXPECT
Too many nested open parens in regex; marked by <-- HERE in m/(( <-- HERE a))/ at - line 3.
########
# NAME \K not permitted in lookahead
-$x =~ /(?=a\Ka)a/;
+qr/(?=a\Ka)a/;
EXPECT
\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in m/(?=a\K <-- HERE a)a/ at - line 1.
########
+# NAME \K not permitted in lookahead (alpha)
+no warnings 'experimental::alpha_assertions';
+qr/(*positive_lookahead:a\Ka)a/;
+EXPECT
+\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in m/(*positive_lookahead:a\K <-- HERE a)a/ at - line 2.
+########
+# NAME \K not permitted in negative lookahead
+qr/(?!a\Ka)a/;
+EXPECT
+\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in m/(?!a\K <-- HERE a)a/ at - line 1.
+########
+# NAME \K not permitted in negative lookahead (alpha)
+no warnings 'experimental::alpha_assertions';
+qr/(*negative_lookahead:a\Ka)a/;
+EXPECT
+\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in m/(*negative_lookahead:a\K <-- HERE a)a/ at - line 2.
+########
# NAME \K not permitted in lookbehind
-$x =~ /(?<=a\Ka)a/;
+qr/(?<=a\Ka)a/;
EXPECT
\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in m/(?<=a\K <-- HERE a)a/ at - line 1.
########
+# NAME \K not permitted in lookbehind (alpha)
+no warnings 'experimental::alpha_assertions';
+qr/(*positive_lookbehind:a\Ka)a/;
+EXPECT
+\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in m/(*positive_lookbehind:a\K <-- HERE a)a/ at - line 2.
+########
+# NAME \K not permitted in negative lookbehind
+qr/(?<!a\Ka)a/;
+EXPECT
+\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in m/(?<!a\K <-- HERE a)a/ at - line 1.
+########
+# NAME \K not permitted in negative lookbehind (alpha)
+no warnings 'experimental::alpha_assertions';
+qr/(*negative_lookbehind:a\Ka)a/;
+EXPECT
+\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in m/(*negative_lookbehind:a\K <-- HERE a)a/ at - line 2.
+########
+# NAME \K is permitted after the lookahead GH#18123
+qr/(?=(?=x)x)\K/;
+EXPECT
+OPTIONS nonfatal
+########
# NAME numeric parsing buffer overflow in numeric.c
0=~/\p{nV:-0}/
EXPECT