summaryrefslogtreecommitdiff
path: root/t/re
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2013-06-07 18:14:43 -0700
committerFather Chrysostomos <sprout@cpan.org>2013-06-07 18:17:58 -0700
commit1cb2b5d4ff78efbd407ee199ed0ed9ff0227cecb (patch)
treeba25eeada61fd76dffe69c46d3e67139328e54ac /t/re
parent8b6fbf55492d62755d8dabe8593bae6befddd121 (diff)
downloadperl-1cb2b5d4ff78efbd407ee199ed0ed9ff0227cecb.tar.gz
Allow qr/(?[ [a] ])/ interpolation in (?[...])
Interpolation fails if the interpolated extended character class con- tains any bracketed character classes itself. The sizing pass looks for [ and passes control to the regular charac- ter class parser. When the charclass is finished, it begins scanning for [ again. If it finds ], it assumes it is the end. That fails with (?[ (?a:(?[ [a] ])) ]). The sizing pass hands [ [a] ]... off to the charclass parser, which parses [ [a] and hands control back to the sizing pass. It then sees ‘ ])) ])’, assumes that the first ]) is the end of the entire construct, so the main regexp parser sees the parenthesis following and dies. If we change the sizing pass to look for ?[ we can simply record the depth (depth++) and then when we see ] decrement the depth or exist the loop if it is zero.
Diffstat (limited to 't/re')
-rw-r--r--t/re/regex_sets.t3
1 files changed, 3 insertions, 0 deletions
diff --git a/t/re/regex_sets.t b/t/re/regex_sets.t
index b70e7ec0c2..9ddceae577 100644
--- a/t/re/regex_sets.t
+++ b/t/re/regex_sets.t
@@ -85,6 +85,9 @@ my $still_fold = qr/(?[ $kelvin_fold ])/;
like("K", $still_fold, "/i on interpolated (?[ ]) is retained in outer without /i");
like("k", $still_fold, "/i on interpolated (?[ ]) is retained in outer without /i");
+eval 'my $x = qr/(?[ [a] ])/; qr/(?[ $x ])/';
+is($@, "", 'qr/(?[ [a] ])/ can be interpolated');
+
done_testing();
1;