This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add regnode LEXACT, for long strings
[perl5.git] / t / re / pat.t
CommitLineData
8d063cd8 1#!./perl
8d37f932
DD
2#
3# This is a home for regular expression tests that don't fit into
67a2b8c6 4# the format supported by re/regexp.t. If you want to add a test
9fa196e1 5# that does fit that format, add it to re/re_tests, not here.
8d063cd8 6
84281c31
A
7use strict;
8use warnings;
2abbd513 9no warnings 'experimental::vlb';
84281c31
A
10use 5.010;
11
84281c31
A
12sub run_tests;
13
9133bbab 14$| = 1;
3568d838 15
8d37f932 16
e4d48cc9
GS
17BEGIN {
18 chdir 't' if -d 't';
569f7fc5 19 require Config; import Config;
6d937e95 20 require './test.pl'; require './charset_tools.pl';
ef9d5242 21 require './loc_tools.pl';
624c42e2
N
22 set_up_inc('../lib', '.', '../ext/re');
23}
99956112
KW
24
25skip_all('no re module') unless defined &DynaLoader::boot_DynaLoader;
26skip_all_without_unicode_tables();
84281c31 27
3ae8ec47 28plan tests => 960; # Update this when adding/deleting tests.
b7a35066 29
9d45b377 30run_tests() unless caller;
b7a35066 31
84281c31
A
32#
33# Tests start here.
34#
35sub run_tests {
f8fb8615
KW
36 my $sharp_s = uni_to_native("\xdf");
37
84281c31 38 {
84281c31 39 my $x = "abc\ndef\n";
5895685f 40 (my $x_pretty = $x) =~ s/\n/\\n/g;
fd291da9 41
5895685f
NC
42 ok $x =~ /^abc/, qq ["$x_pretty" =~ /^abc/];
43 ok $x !~ /^def/, qq ["$x_pretty" !~ /^def/];
fd291da9 44
84281c31 45 # used to be a test for $*
5895685f 46 ok $x =~ /^def/m, qq ["$x_pretty" =~ /^def/m];
fd291da9 47
b33825c4
NC
48 ok(!($x =~ /^xxx/), qq ["$x_pretty" =~ /^xxx/]);
49 ok(!($x !~ /^abc/), qq ["$x_pretty" !~ /^abc/]);
fd291da9 50
5895685f 51 ok $x =~ /def/, qq ["$x_pretty" =~ /def/];
b33825c4 52 ok(!($x !~ /def/), qq ["$x_pretty" !~ /def/]);
4765795a 53
5895685f 54 ok $x !~ /.def/, qq ["$x_pretty" !~ /.def/];
b33825c4 55 ok(!($x =~ /.def/), qq ["$x_pretty" =~ /.def/]);
4765795a 56
5895685f 57 ok $x =~ /\ndef/, qq ["$x_pretty" =~ /\\ndef/];
b33825c4 58 ok(!($x !~ /\ndef/), qq ["$x_pretty" !~ /\\ndef/]);
84281c31 59 }
4765795a 60
84281c31
A
61 {
62 $_ = '123';
63 ok /^([0-9][0-9]*)/, qq [\$_ = '$_'; /^([0-9][0-9]*)/];
64 }
f9969324 65
84281c31
A
66 {
67 $_ = 'aaabbbccc';
68 ok /(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc',
69 qq [\$_ = '$_'; /(a*b*)(c*)/];
70 ok /(a+b+c+)/ && $1 eq 'aaabbbccc', qq [\$_ = '$_'; /(a+b+c+)/];
b33825c4 71 unlike($_, qr/a+b?c+/, qq [\$_ = '$_'; /a+b?c+/]);
84281c31
A
72
73 $_ = 'aaabccc';
74 ok /a+b?c+/, qq [\$_ = '$_'; /a+b?c+/];
75 ok /a*b?c*/, qq [\$_ = '$_'; /a*b?c*/];
76
77 $_ = 'aaaccc';
78 ok /a*b?c*/, qq [\$_ = '$_'; /a*b?c*/];
b33825c4 79 unlike($_, qr/a*b+c*/, qq [\$_ = '$_'; /a*b+c*/]);
84281c31
A
80
81 $_ = 'abcdef';
82 ok /bcd|xyz/, qq [\$_ = '$_'; /bcd|xyz/];
83 ok /xyz|bcd/, qq [\$_ = '$_'; /xyz|bcd/];
84 ok m|bc/*d|, qq [\$_ = '$_'; m|bc/*d|];
85 ok /^$_$/, qq [\$_ = '$_'; /^\$_\$/];
4765795a 86 }
4765795a 87
84281c31
A
88 {
89 # used to be a test for $*
5895685f 90 ok "ab\ncd\n" =~ /^cd/m, q ["ab\ncd\n" =~ /^cd/m];
84281c31 91 }
4765795a 92
84281c31
A
93 {
94 our %XXX = map {($_ => $_)} 123, 234, 345;
95
96 our @XXX = ('ok 1','not ok 1', 'ok 2','not ok 2','not ok 3');
97 while ($_ = shift(@XXX)) {
b33825c4 98 my $e = index ($_, 'not') >= 0 ? '' : 1;
725a61d7 99 my $r = m?(.*)?;
b33825c4 100 is($r, $e, "?(.*)?");
84281c31
A
101 /not/ && reset;
102 if (/not ok 2/) {
103 if ($^O eq 'VMS') {
104 $_ = shift(@XXX);
105 }
106 else {
107 reset 'X';
108 }
109 }
110 }
4765795a 111
84281c31
A
112 SKIP: {
113 if ($^O eq 'VMS') {
114 skip "Reset 'X'", 1;
115 }
116 ok !keys %XXX, "%XXX is empty";
117 }
4765795a 118
84281c31 119 }
4765795a 120
84281c31 121 {
4f890a30 122 my $message = "Test empty pattern";
84281c31
A
123 my $xyz = 'xyz';
124 my $cde = 'cde';
125
126 $cde =~ /[^ab]*/;
127 $xyz =~ //;
4f890a30 128 is($&, $xyz, $message);
84281c31
A
129
130 my $foo = '[^ab]*';
131 $cde =~ /$foo/;
132 $xyz =~ //;
4f890a30 133 is($&, $xyz, $message);
84281c31
A
134
135 $cde =~ /$foo/;
136 my $null;
137 no warnings 'uninitialized';
138 $xyz =~ /$null/;
4f890a30 139 is($&, $xyz, $message);
84281c31
A
140
141 $null = "";
142 $xyz =~ /$null/;
4f890a30 143 is($&, $xyz, $message);
3cb4cde3
TC
144
145 # each entry: regexp, match string, $&, //o match success
146 my @tests =
147 (
148 [ "", "xy", "x", 1 ],
149 [ "y", "yz", "y", !1 ],
150 );
151 for my $test (@tests) {
152 my ($re, $str, $matched, $omatch) = @$test;
153 $xyz =~ /x/o;
154 ok($str =~ /$re/, "$str matches /$re/");
155 is($&, $matched, "on $matched");
156 $xyz =~ /x/o;
157 is($str =~ /$re/o, $omatch, "$str matches /$re/o (or not)");
158 }
84281c31 159 }
4765795a 160
84281c31 161 {
4f890a30 162 my $message = q !Check $`, $&, $'!;
84281c31 163 $_ = 'abcdefghi';
0f289c68 164 /def/; # optimized up to cmd
4f890a30 165 is("$`:$&:$'", 'abc:def:ghi', $message);
4765795a 166
84281c31 167 no warnings 'void';
0f289c68 168 /cde/ + 0; # optimized only to spat
4f890a30 169 is("$`:$&:$'", 'ab:cde:fghi', $message);
4765795a 170
0f289c68 171 /[d][e][f]/; # not optimized
4f890a30 172 is("$`:$&:$'", 'abc:def:ghi', $message);
84281c31 173 }
4765795a 174
84281c31
A
175 {
176 $_ = 'now is the {time for all} good men to come to.';
2a53d331 177 / \{([^}]*)}/;
de26e0cc 178 is($1, 'time for all', "Match braces");
84281c31 179 }
4765795a 180
84281c31 181 {
4f890a30 182 my $message = "{N,M} quantifier";
84281c31 183 $_ = 'xxx {3,4} yyy zzz';
4f890a30
NC
184 ok(/( {3,4})/, $message);
185 is($1, ' ', $message);
186 unlike($_, qr/( {4,})/, $message);
187 ok(/( {2,3}.)/, $message);
188 is($1, ' y', $message);
189 ok(/(y{2,3}.)/, $message);
190 is($1, 'yyy ', $message);
191 unlike($_, qr/x {3,4}/, $message);
192 unlike($_, qr/^xxx {3,4}/, $message);
84281c31 193 }
4765795a 194
84281c31 195 {
4f890a30 196 my $message = "Test /g";
84281c31
A
197 local $" = ":";
198 $_ = "now is the time for all good men to come to.";
199 my @words = /(\w+)/g;
200 my $exp = "now:is:the:time:for:all:good:men:to:come:to";
4765795a 201
4f890a30 202 is("@words", $exp, $message);
4765795a 203
84281c31
A
204 @words = ();
205 while (/\w+/g) {
206 push (@words, $&);
207 }
4f890a30 208 is("@words", $exp, $message);
4765795a 209
84281c31
A
210 @words = ();
211 pos = 0;
212 while (/to/g) {
213 push(@words, $&);
214 }
4f890a30 215 is("@words", "to:to", $message);
4765795a 216
84281c31
A
217 pos $_ = 0;
218 @words = /to/g;
4f890a30 219 is("@words", "to:to", $message);
84281c31 220 }
4765795a 221
84281c31
A
222 {
223 $_ = "abcdefghi";
224
225 my $pat1 = 'def';
226 my $pat2 = '^def';
227 my $pat3 = '.def.';
228 my $pat4 = 'abc';
229 my $pat5 = '^abc';
230 my $pat6 = 'abc$';
231 my $pat7 = 'ghi';
232 my $pat8 = '\w*ghi';
233 my $pat9 = 'ghi$';
234
235 my $t1 = my $t2 = my $t3 = my $t4 = my $t5 =
236 my $t6 = my $t7 = my $t8 = my $t9 = 0;
237
238 for my $iter (1 .. 5) {
239 $t1++ if /$pat1/o;
240 $t2++ if /$pat2/o;
241 $t3++ if /$pat3/o;
242 $t4++ if /$pat4/o;
243 $t5++ if /$pat5/o;
244 $t6++ if /$pat6/o;
245 $t7++ if /$pat7/o;
246 $t8++ if /$pat8/o;
247 $t9++ if /$pat9/o;
248 }
249 my $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
de26e0cc 250 is($x, '505550555', "Test /o");
84281c31 251 }
4765795a 252
4f890a30 253 {
84281c31
A
254 my $xyz = 'xyz';
255 ok "abc" =~ /^abc$|$xyz/, "| after \$";
4765795a 256
84281c31 257 # perl 4.009 says "unmatched ()"
4f890a30 258 my $message = '$ inside ()';
4765795a 259
84281c31
A
260 my $result;
261 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
4f890a30
NC
262 is($@, "", $message);
263 is($result, "abc:bc", $message);
84281c31 264 }
4765795a 265
84281c31 266 {
4f890a30 267 my $message = "Scalar /g";
84281c31
A
268 $_ = "abcfooabcbar";
269
4f890a30
NC
270 ok( /abc/g && $` eq "", $message);
271 ok( /abc/g && $` eq "abcfoo", $message);
272 ok(!/abc/g, $message);
84281c31 273
4f890a30 274 $message = "Scalar /gi";
84281c31 275 pos = 0;
4f890a30
NC
276 ok( /ABC/gi && $` eq "", $message);
277 ok( /ABC/gi && $` eq "abcfoo", $message);
278 ok(!/ABC/gi, $message);
84281c31 279
4f890a30 280 $message = "Scalar /g";
84281c31 281 pos = 0;
4f890a30
NC
282 ok( /abc/g && $' eq "fooabcbar", $message);
283 ok( /abc/g && $' eq "bar", $message);
84281c31
A
284
285 $_ .= '';
286 my @x = /abc/g;
de26e0cc 287 is(@x, 2, "/g reset after assignment");
4765795a 288 }
4765795a 289
84281c31 290 {
4f890a30 291 my $message = '/g, \G and pos';
84281c31
A
292 $_ = "abdc";
293 pos $_ = 2;
294 /\Gc/gc;
4f890a30 295 is(pos $_, 2, $message);
84281c31 296 /\Gc/g;
4f890a30 297 is(pos $_, undef, $message);
84281c31 298 }
4765795a 299
84281c31 300 {
4f890a30 301 my $message = '(?{ })';
84281c31
A
302 our $out = 1;
303 'abc' =~ m'a(?{ $out = 2 })b';
4f890a30 304 is($out, 2, $message);
84281c31
A
305
306 $out = 1;
307 'abc' =~ m'a(?{ $out = 3 })c';
4f890a30 308 is($out, 1, $message);
84281c31 309 }
4765795a 310
84281c31
A
311 {
312 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
313 my @out = /(?<!foo)bar./g;
de26e0cc 314 is("@out", 'bar2 barf', "Negative lookbehind");
84281c31 315 }
4765795a 316
84281c31 317 {
4f890a30 318 my $message = "REG_INFTY tests";
84281c31 319 # Tests which depend on REG_INFTY
19d6612d
NC
320
321 # Defaults assumed if this fails
322 eval { require Config; };
4288c5b9 323 $::reg_infty = $Config::Config{reg_infty} // 65535;
84281c31
A
324 $::reg_infty_m = $::reg_infty - 1;
325 $::reg_infty_p = $::reg_infty + 1;
93f09d7b 326 $::reg_infty_m = $::reg_infty_m; # Suppress warning.
84281c31
A
327
328 # As well as failing if the pattern matches do unexpected things, the
329 # next three tests will fail if you should have picked up a lower-than-
330 # default value for $reg_infty from Config.pm, but have not.
331
14358a41
NC
332 is(eval q{('aaa' =~ /(a{1,$::reg_infty_m})/)[0]}, 'aaa', $message);
333 is($@, '', $message);
334 is(eval q{('a' x $::reg_infty_m) =~ /a{$::reg_infty_m}/}, 1, $message);
335 is($@, '', $message);
336 isnt(q{('a' x ($::reg_infty_m - 1)) !~ /a{$::reg_infty_m}/}, 1, $message);
337 is($@, '', $message);
338
84281c31 339 eval "'aaa' =~ /a{1,$::reg_infty}/";
224b2e7e 340 like($@, qr/^\QQuantifier in {,} bigger than/, $message);
84281c31 341 eval "'aaa' =~ /a{1,$::reg_infty_p}/";
4f890a30 342 like($@, qr/^\QQuantifier in {,} bigger than/, $message);
cc27c3b3
KW
343
344 # It should be 'a' x 2147483647, but that exhausts memory on
345 # reasonably sized modern machines
346 like('a' x $::reg_infty_p, qr/a{1,}/,
347 "{1,} matches more times than REG_INFTY");
4765795a 348 }
8269fa76 349
84281c31
A
350 {
351 # Poke a couple more parse failures
352 my $context = 'x' x 256;
353 eval qq("${context}y" =~ /(?<=$context)y/);
354 ok $@ =~ /^\QLookbehind longer than 255 not/, "Lookbehind limit";
355 }
8269fa76 356
84281c31
A
357 {
358 # Long Monsters
84281c31
A
359 for my $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
360 my $a = 'a' x $l;
4f890a30
NC
361 my $message = "Long monster, length = $l";
362 like("ba$a=", qr/a$a=/, $message);
363 unlike("b$a=", qr/a$a=/, $message);
364 like("b$a=", qr/ba+=/, $message);
84281c31 365
224b2e7e 366 like("ba$a=", qr/b(?:a|b)+=/, $message);
84281c31
A
367 }
368 }
8269fa76 369
84281c31
A
370 {
371 # 20000 nodes, each taking 3 words per string, and 1 per branch
372 my $long_constant_len = join '|', 12120 .. 32645;
373 my $long_var_len = join '|', 8120 .. 28645;
374 my %ans = ( 'ax13876y25677lbc' => 1,
375 'ax13876y25677mcb' => 0, # not b.
376 'ax13876y35677nbc' => 0, # Num too big
377 'ax13876y25677y21378obc' => 1,
0f289c68 378 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
84281c31
A
379 'ax13876y25677y21378y21378kbc' => 1,
380 'ax13876y25677y21378y21378kcb' => 0, # Not b.
381 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
382 );
383
84281c31 384 for (keys %ans) {
4f890a30
NC
385 my $message = "20000 nodes, const-len '$_'";
386 ok !($ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o), $message;
84281c31 387
4f890a30
NC
388 $message = "20000 nodes, var-len '$_'";
389 ok !($ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o,), $message;
84281c31 390 }
b8ef571c 391 }
209a9bc1 392
84281c31 393 {
4f890a30 394 my $message = "Complicated backtracking";
84281c31
A
395 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
396 my $expect = "(bla()) ((l)u((e))) (l(e)e)";
397
83461ff8 398 our $c;
84281c31
A
399 sub matchit {
400 m/
401 (
402 \(
0f289c68 403 (?{ $c = 1 }) # Initialize
84281c31
A
404 (?:
405 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
406 (?!
0f289c68
YO
407 ) # Fail: will unwind one iteration back
408 )
84281c31 409 (?:
0f289c68 410 [^()]+ # Match a big chunk
84281c31
A
411 (?=
412 [()]
0f289c68 413 ) # Do not try to match subchunks
84281c31
A
414 |
415 \(
416 (?{ ++$c })
417 |
418 \)
419 (?{ --$c })
420 )
0f289c68 421 )+ # This may not match with different subblocks
84281c31
A
422 )
423 (?(?{ $c != 0 })
424 (?!
0f289c68
YO
425 ) # Fail
426 ) # Otherwise the chunk 1 may succeed with $c>0
84281c31
A
427 /xg;
428 }
3568d838 429
84281c31
A
430 my @ans = ();
431 my $res;
432 push @ans, $res while $res = matchit;
4f890a30 433 is("@ans", "1 1 1", $message);
3568d838 434
84281c31 435 @ans = matchit;
4f890a30 436 is("@ans", $expect, $message);
3568d838 437
4f890a30 438 $message = "Recursion with (??{ })";
84281c31
A
439 our $matched;
440 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
3568d838 441
84281c31
A
442 @ans = my @ans1 = ();
443 push (@ans, $res), push (@ans1, $&) while $res = m/$matched/g;
3568d838 444
4f890a30
NC
445 is("@ans", "1 1 1", $message);
446 is("@ans1", $expect, $message);
3568d838 447
84281c31 448 @ans = m/$matched/g;
4f890a30 449 is("@ans", $expect, $message);
3568d838 450
84281c31 451 }
3568d838 452
84281c31
A
453 {
454 ok "abc" =~ /^(??{"a"})b/, '"abc" =~ /^(??{"a"})b/';
455 }
3568d838 456
84281c31 457 {
0f289c68 458 my @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
de26e0cc 459 is("@ans", 'a/ b', "Stack may be bad");
84281c31 460 }
3568d838 461
84281c31 462 {
4f890a30 463 my $message = "Eval-group not allowed at runtime";
84281c31
A
464 my $code = '{$blah = 45}';
465 our $blah = 12;
466 eval { /(?$code)/ };
4f890a30 467 ok($@ && $@ =~ /not allowed at runtime/ && $blah == 12, $message);
84281c31 468
3044771b
NC
469 $blah = 12;
470 my $res = eval { "xx" =~ /(?$code)/o };
471 {
472 no warnings 'uninitialized';
5895685f 473 chomp $@; my $message = "$message '$@', '$res', '$blah'";
4f890a30 474 ok($@ && $@ =~ /not allowed at runtime/ && $blah == 12, $message);
3044771b
NC
475 }
476
477 $code = '=xx';
478 $blah = 12;
479 $res = eval { "xx" =~ /(?$code)/o };
480 {
481 no warnings 'uninitialized';
4f890a30
NC
482 my $message = "$message '$@', '$res', '$blah'";
483 ok(!$@ && $res, $message);
3044771b 484 }
3568d838 485
84281c31
A
486 $code = '{$blah = 45}';
487 $blah = 12;
488 eval "/(?$code)/";
4f890a30 489 is($blah, 45, $message);
3568d838 490
84281c31
A
491 $blah = 12;
492 /(?{$blah = 45})/;
4f890a30 493 is($blah, 45, $message);
84281c31 494 }
3568d838 495
84281c31 496 {
4f890a30 497 my $message = "Pos checks";
84281c31
A
498 my $x = 'banana';
499 $x =~ /.a/g;
4f890a30 500 is(pos $x, 2, $message);
3568d838 501
84281c31 502 $x =~ /.z/gc;
4f890a30 503 is(pos $x, 2, $message);
3568d838 504
84281c31
A
505 sub f {
506 my $p = $_[0];
507 return $p;
508 }
3568d838 509
84281c31 510 $x =~ /.a/g;
4f890a30 511 is(f (pos $x), 4, $message);
84281c31 512 }
3568d838 513
84281c31 514 {
4f890a30 515 my $message = 'Checking $^R';
84281c31
A
516 our $x = $^R = 67;
517 'foot' =~ /foo(?{$x = 12; 75})[t]/;
4f890a30 518 is($^R, 75, $message);
84281c31
A
519
520 $x = $^R = 67;
521 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
4f890a30 522 ok($^R eq '67' && $x eq '12', $message);
84281c31
A
523
524 $x = $^R = 67;
525 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
4f890a30 526 ok($^R eq '79' && $x eq '12', $message);
84281c31 527 }
3568d838 528
84281c31 529 {
de26e0cc
NC
530 is(qr/\b\v$/i, '(?^i:\b\v$)', 'qr/\b\v$/i');
531 is(qr/\b\v$/s, '(?^s:\b\v$)', 'qr/\b\v$/s');
532 is(qr/\b\v$/m, '(?^m:\b\v$)', 'qr/\b\v$/m');
533 is(qr/\b\v$/x, '(?^x:\b\v$)', 'qr/\b\v$/x');
534 is(qr/\b\v$/xism, '(?^msix:\b\v$)', 'qr/\b\v$/xism');
535 is(qr/\b\v$/, '(?^:\b\v$)', 'qr/\b\v$/');
84281c31 536 }
3568d838 537
9de15fec 538 { # Test that charset modifier work, and are interpolated
de26e0cc
NC
539 is(qr/\b\v$/, '(?^:\b\v$)', 'Verify no locale, no unicode_strings gives default modifier');
540 is(qr/(?l:\b\v$)/, '(?^:(?l:\b\v$))', 'Verify infix l modifier compiles');
541 is(qr/(?u:\b\v$)/, '(?^:(?u:\b\v$))', 'Verify infix u modifier compiles');
542 is(qr/(?l)\b\v$/, '(?^:(?l)\b\v$)', 'Verify (?l) compiles');
543 is(qr/(?u)\b\v$/, '(?^:(?u)\b\v$)', 'Verify (?u) compiles');
9de15fec
KW
544
545 my $dual = qr/\b\v$/;
569f7fc5
JR
546 my $locale;
547
548 SKIP: {
ef9d5242 549 skip 'Locales not available', 1 unless locales_enabled('LC_CTYPE');
569f7fc5 550
5f1269ab 551 use locale;
569f7fc5
JR
552 $locale = qr/\b\v$/;
553 is($locale, '(?^l:\b\v$)', 'Verify has l modifier when compiled under use locale');
554 no locale;
555 }
9de15fec
KW
556
557 use feature 'unicode_strings';
558 my $unicode = qr/\b\v$/;
de26e0cc
NC
559 is($unicode, '(?^u:\b\v$)', 'Verify has u modifier when compiled under unicode_strings');
560 is(qr/abc$dual/, '(?^u:abc(?^:\b\v$))', 'Verify retains d meaning when interpolated under locale');
569f7fc5
JR
561
562 SKIP: {
ef9d5242 563 skip 'Locales not available', 1 unless locales_enabled('LC_CTYPE');
569f7fc5
JR
564
565 is(qr/abc$locale/, '(?^u:abc(?^l:\b\v$))', 'Verify retains l when interpolated under unicode_strings');
566 }
9de15fec
KW
567
568 no feature 'unicode_strings';
569f7fc5 569 SKIP: {
ef9d5242 570 skip 'Locales not available', 1 unless locales_enabled('LC_CTYPE');
569f7fc5
JR
571 is(qr/abc$locale/, '(?^:abc(?^l:\b\v$))', 'Verify retains l when interpolated outside locale and unicode strings');
572 }
573
de26e0cc 574 is(qr/def$unicode/, '(?^:def(?^u:\b\v$))', 'Verify retains u when interpolated outside locale and unicode strings');
9de15fec 575
569f7fc5 576 SKIP: {
ef9d5242 577 skip 'Locales not available', 2 unless locales_enabled('LC_CTYPE');
569f7fc5 578
5f1269ab 579 use locale;
569f7fc5
JR
580 is(qr/abc$dual/, '(?^l:abc(?^:\b\v$))', 'Verify retains d meaning when interpolated under locale');
581 is(qr/abc$unicode/, '(?^l:abc(?^u:\b\v$))', 'Verify retains u when interpolated under locale');
582 }
9de15fec
KW
583 }
584
84281c31 585 {
4f890a30 586 my $message = "Look around";
84281c31 587 $_ = 'xabcx';
84281c31 588 foreach my $ans ('', 'c') {
4f890a30
NC
589 ok(/(?<=(?=a)..)((?=c)|.)/g, $message);
590 is($1, $ans, $message);
84281c31
A
591 }
592 }
3568d838 593
84281c31 594 {
4f890a30 595 my $message = "Empty clause";
84281c31
A
596 $_ = 'a';
597 foreach my $ans ('', 'a', '') {
4f890a30
NC
598 ok(/^|a|$/g, $message);
599 is($&, $ans, $message);
84281c31
A
600 }
601 }
3568d838 602
84281c31 603 {
84281c31 604 sub prefixify {
4f890a30
NC
605 my $message = "Prefixify";
606 {
84281c31 607 my ($v, $a, $b, $res) = @_;
4f890a30
NC
608 ok($v =~ s/\Q$a\E/$b/, $message);
609 is($v, $res, $message);
84281c31
A
610 }
611 }
3568d838 612
84281c31
A
613 prefixify ('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
614 prefixify ('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
615 }
3568d838 616
84281c31
A
617 {
618 $_ = 'var="foo"';
619 /(\")/;
620 ok $1 && /$1/, "Capture a quote";
621 }
3568d838 622
84281c31 623 {
84281c31 624 no warnings 'closure';
4f890a30 625 my $message = '(?{ $var } refers to package vars';
84281c31
A
626 package aa;
627 our $c = 2;
628 $::c = 3;
629 '' =~ /(?{ $c = 4 })/;
4f890a30
NC
630 main::is($c, 4, $message);
631 main::is($::c, 3, $message);
84281c31 632 }
3568d838 633
84281c31 634 {
cb124425
NC
635 is(eval 'q(a:[b]:) =~ /[x[:foo:]]/', undef);
636 like ($@, qr/POSIX class \[:[^:]+:\] unknown in regex/,
637 'POSIX class [: :] must have valid name');
84281c31
A
638
639 for my $d (qw [= .]) {
cb124425
NC
640 is(eval "/[[${d}foo${d}]]/", undef);
641 like ($@, qr/\QPOSIX syntax [$d $d] is reserved for future extensions/,
642 "POSIX syntax [[$d $d]] is an error");
84281c31
A
643 }
644 }
3568d838 645
84281c31
A
646 {
647 # test if failure of patterns returns empty list
4f890a30 648 my $message = "Failed pattern returns empty list";
84281c31
A
649 $_ = 'aaa';
650 @_ = /bbb/;
4f890a30 651 is("@_", "", $message);
3568d838 652
84281c31 653 @_ = /bbb/g;
4f890a30 654 is("@_", "", $message);
a72deede 655
84281c31 656 @_ = /(bbb)/;
4f890a30 657 is("@_", "", $message);
a72deede 658
84281c31 659 @_ = /(bbb)/g;
4f890a30 660 is("@_", "", $message);
84281c31 661 }
a72deede 662
84281c31 663 {
27deb0cf 664 my $message = '@- and @+ and @{^CAPTURE} tests';
84281c31 665
27deb0cf
YO
666 $_= "ace";
667 /c(?=.$)/;
668 is($#{^CAPTURE}, -1, $message);
4f890a30
NC
669 is($#+, 0, $message);
670 is($#-, 0, $message);
671 is($+ [0], 2, $message);
672 is($- [0], 1, $message);
673 ok(!defined $+ [1] && !defined $- [1] &&
674 !defined $+ [2] && !defined $- [2], $message);
84281c31 675
27deb0cf
YO
676 /a(c)(e)/;
677 is($#{^CAPTURE}, 1, $message); # one less than $#-
4f890a30
NC
678 is($#+, 2, $message);
679 is($#-, 2, $message);
680 is($+ [0], 3, $message);
681 is($- [0], 0, $message);
27deb0cf 682 is(${^CAPTURE}[0], "c", $message);
4f890a30
NC
683 is($+ [1], 2, $message);
684 is($- [1], 1, $message);
27deb0cf 685 is(${^CAPTURE}[1], "e", $message);
4f890a30
NC
686 is($+ [2], 3, $message);
687 is($- [2], 2, $message);
688 ok(!defined $+ [3] && !defined $- [3] &&
27deb0cf 689 !defined ${^CAPTURE}[2] && !defined ${^CAPTURE}[3] &&
4f890a30 690 !defined $+ [4] && !defined $- [4], $message);
84281c31 691
54a4274e 692 # Exists has a special check for @-/@+ - bug 45147
4f890a30
NC
693 ok(exists $-[0], $message);
694 ok(exists $+[0], $message);
27deb0cf
YO
695 ok(exists ${^CAPTURE}[0], $message);
696 ok(exists ${^CAPTURE}[1], $message);
4f890a30
NC
697 ok(exists $-[2], $message);
698 ok(exists $+[2], $message);
27deb0cf 699 ok(!exists ${^CAPTURE}[2], $message);
4f890a30
NC
700 ok(!exists $-[3], $message);
701 ok(!exists $+[3], $message);
27deb0cf
YO
702 ok(exists ${^CAPTURE}[-1], $message);
703 ok(exists ${^CAPTURE}[-2], $message);
4f890a30
NC
704 ok(exists $-[-1], $message);
705 ok(exists $+[-1], $message);
706 ok(exists $-[-3], $message);
707 ok(exists $+[-3], $message);
708 ok(!exists $-[-4], $message);
709 ok(!exists $+[-4], $message);
27deb0cf 710 ok(!exists ${^CAPTURE}[-3], $message);
84281c31 711
27deb0cf
YO
712
713 /.(c)(b)?(e)/;
714 is($#{^CAPTURE}, 2, $message); # one less than $#-
4f890a30
NC
715 is($#+, 3, $message);
716 is($#-, 3, $message);
27deb0cf
YO
717 is(${^CAPTURE}[0], "c", $message);
718 is(${^CAPTURE}[2], "e", $message . "[$1 $3]");
4f890a30
NC
719 is($+ [1], 2, $message);
720 is($- [1], 1, $message);
721 is($+ [3], 3, $message);
722 is($- [3], 2, $message);
723 ok(!defined $+ [2] && !defined $- [2] &&
27deb0cf
YO
724 !defined $+ [4] && !defined $- [4] &&
725 !defined ${^CAPTURE}[1], $message);
84281c31 726
27deb0cf
YO
727 /.(c)/;
728 is($#{^CAPTURE}, 0, $message); # one less than $#-
4f890a30
NC
729 is($#+, 1, $message);
730 is($#-, 1, $message);
27deb0cf 731 is(${^CAPTURE}[0], "c", $message);
4f890a30
NC
732 is($+ [0], 2, $message);
733 is($- [0], 0, $message);
734 is($+ [1], 2, $message);
735 is($- [1], 1, $message);
736 ok(!defined $+ [2] && !defined $- [2] &&
27deb0cf
YO
737 !defined $+ [3] && !defined $- [3] &&
738 !defined ${^CAPTURE}[1], $message);
84281c31 739
27deb0cf
YO
740 /.(c)(ba*)?/;
741 is($#{^CAPTURE}, 0, $message); # one less than $#-
4f890a30
NC
742 is($#+, 2, $message);
743 is($#-, 1, $message);
232af1f8 744
150fa1c5 745 # Check that values don't stick
232af1f8 746 " "=~/()()()(.)(..)/;
27deb0cf
YO
747 my($m,$p,$q) = (\$-[5], \$+[5], \${^CAPTURE}[4]);
748 () = "$$_" for $m, $p, $q; # FETCH (or eqv.)
232af1f8
FC
749 " " =~ /()/;
750 is $$m, undef, 'values do not stick to @- elements';
751 is $$p, undef, 'values do not stick to @+ elements';
27deb0cf 752 is $$q, undef, 'values do not stick to @{^CAPTURE} elements';
84281c31 753 }
a72deede 754
d9bad346 755 foreach ('$+[0] = 13', '$-[0] = 13', '@+ = (7, 6, 5)',
27deb0cf 756 '${^CAPTURE}[0] = 13',
d9bad346 757 '@- = qw (foo bar)', '$^N = 42') {
cb124425
NC
758 is(eval $_, undef);
759 like($@, qr/^Modification of a read-only value attempted/,
d9bad346 760 '$^N, @- and @+ are read-only');
84281c31 761 }
a72deede 762
84281c31 763 {
4f890a30 764 my $message = '\G testing';
84281c31
A
765 $_ = 'aaa';
766 pos = 1;
767 my @a = /\Ga/g;
4f890a30 768 is("@a", "a a", $message);
84281c31
A
769
770 my $str = 'abcde';
771 pos $str = 2;
4f890a30
NC
772 unlike($str, qr/^\G/, $message);
773 unlike($str, qr/^.\G/, $message);
774 like($str, qr/^..\G/, $message);
775 unlike($str, qr/^...\G/, $message);
776 ok($str =~ /\G../ && $& eq 'cd', $message);
4f890a30 777 ok($str =~ /.\G./ && $& eq 'bc', $message);
cf44e600
DM
778
779 }
780
781 {
782 my $message = '\G and intuit and anchoring';
783 $_ = "abcdef";
784 pos = 0;
785 ok($_ =~ /\Gabc/, $message);
786 ok($_ =~ /^\Gabc/, $message);
787
788 pos = 3;
789 ok($_ =~ /\Gdef/, $message);
790 pos = 3;
791 ok($_ =~ /\Gdef$/, $message);
792 pos = 3;
793 ok($_ =~ /abc\Gdef$/, $message);
794 pos = 3;
795 ok($_ =~ /^abc\Gdef$/, $message);
796 pos = 3;
797 ok($_ =~ /c\Gd/, $message);
e0362b86
DM
798 pos = 3;
799 ok($_ =~ /..\GX?def/, $message);
84281c31 800 }
a72deede 801
84281c31 802 {
fe3974be
DM
803 my $s = '123';
804 pos($s) = 1;
805 my @a = $s =~ /(\d)\G/g; # this infinitely looped up till 5.19.1
806 is("@a", "1", '\G looping');
807 }
808
809
810 {
4f890a30 811 my $message = 'pos inside (?{ })';
84281c31
A
812 my $str = 'abcde';
813 our ($foo, $bar);
4f890a30
NC
814 like($str, qr/b(?{$foo = $_; $bar = pos})c/, $message);
815 is($foo, $str, $message);
816 is($bar, 2, $message);
817 is(pos $str, undef, $message);
84281c31
A
818
819 undef $foo;
820 undef $bar;
821 pos $str = undef;
4f890a30
NC
822 ok($str =~ /b(?{$foo = $_; $bar = pos})c/g, $message);
823 is($foo, $str, $message);
824 is($bar, 2, $message);
825 is(pos $str, 3, $message);
84281c31
A
826
827 $_ = $str;
828 undef $foo;
829 undef $bar;
4f890a30
NC
830 like($_, qr/b(?{$foo = $_; $bar = pos})c/, $message);
831 is($foo, $str, $message);
832 is($bar, 2, $message);
84281c31
A
833
834 undef $foo;
835 undef $bar;
4f890a30
NC
836 ok(/b(?{$foo = $_; $bar = pos})c/g, $message);
837 is($foo, $str, $message);
838 is($bar, 2, $message);
839 is(pos, 3, $message);
84281c31
A
840
841 undef $foo;
842 undef $bar;
843 pos = undef;
844 1 while /b(?{$foo = $_; $bar = pos})c/g;
4f890a30
NC
845 is($foo, $str, $message);
846 is($bar, 2, $message);
847 is(pos, undef, $message);
84281c31
A
848
849 undef $foo;
850 undef $bar;
851 $_ = 'abcde|abcde';
4f890a30
NC
852 ok(s/b(?{$foo = $_; $bar = pos})c/x/g, $message);
853 is($foo, 'abcde|abcde', $message);
854 is($bar, 8, $message);
855 is($_, 'axde|axde', $message);
84281c31
A
856
857 # List context:
858 $_ = 'abcde|abcde';
859 our @res;
860 () = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
861 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
4f890a30 862 is("@res", "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'", $message);
84281c31
A
863
864 @res = ();
865 () = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
866 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
4f890a30 867 is("@res", "'' 'ab' 'cde|abcde' " .
84281c31
A
868 "'' 'abc' 'de|abcde' " .
869 "'abcd' 'e|' 'abcde' " .
870 "'abcde|' 'ab' 'cde' " .
4f890a30 871 "'abcde|' 'abc' 'de'", $message);
84281c31 872 }
f33976b4 873
84281c31 874 {
4f890a30 875 my $message = '\G anchor checks';
84281c31
A
876 my $foo = 'aabbccddeeffgg';
877 pos ($foo) = 1;
cce850e4 878
98bee633
DM
879 ok($foo =~ /.\G(..)/g, $message);
880 is($1, 'ab', $message);
cce850e4 881
98bee633
DM
882 pos ($foo) += 1;
883 ok($foo =~ /.\G(..)/g, $message);
884 is($1, 'cc', $message);
cce850e4 885
98bee633
DM
886 pos ($foo) += 1;
887 ok($foo =~ /.\G(..)/g, $message);
888 is($1, 'de', $message);
889
890 ok($foo =~ /\Gef/g, $message);
cce850e4 891
84281c31 892 undef pos $foo;
4f890a30
NC
893 ok($foo =~ /\G(..)/g, $message);
894 is($1, 'aa', $message);
cce850e4 895
4f890a30
NC
896 ok($foo =~ /\G(..)/g, $message);
897 is($1, 'bb', $message);
cce850e4 898
84281c31 899 pos ($foo) = 5;
4f890a30
NC
900 ok($foo =~ /\G(..)/g, $message);
901 is($1, 'cd', $message);
84281c31 902 }
cce850e4 903
84281c31 904 {
9c13586e
DM
905 my $message = 'basic \G floating checks';
906 my $foo = 'aabbccddeeffgg';
907 pos ($foo) = 1;
908
909 ok($foo =~ /a+\G(..)/g, "$message: a+\\G");
910 is($1, 'ab', "$message: ab");
911
912 pos ($foo) += 1;
913 ok($foo =~ /b+\G(..)/g, "$message: b+\\G");
914 is($1, 'cc', "$message: cc");
915
916 pos ($foo) += 1;
917 ok($foo =~ /d+\G(..)/g, "$message: d+\\G");
918 is($1, 'de', "$message: de");
919
920 ok($foo =~ /\Gef/g, "$message: \\Gef");
921
922 pos ($foo) = 1;
923
924 ok($foo =~ /(?=a+\G)(..)/g, "$message: (?a+\\G)");
925 is($1, 'aa', "$message: aa");
926
927 pos ($foo) = 2;
928
929 ok($foo =~ /a(?=a+\G)(..)/g, "$message: a(?=a+\\G)");
930 is($1, 'ab', "$message: ab");
931
932 }
933
934 {
84281c31
A
935 $_ = '123x123';
936 my @res = /(\d*|x)/g;
937 local $" = '|';
de26e0cc 938 is("@res", "123||x|123|", "0 match in alternation");
84281c31 939 }
cce850e4 940
84281c31 941 {
4f890a30 942 my $message = "Match against temporaries (created via pp_helem())" .
84281c31 943 " is safe";
4f890a30
NC
944 ok({foo => "bar\n" . $^X} -> {foo} =~ /^(.*)\n/g, $message);
945 is($1, "bar", $message);
84281c31 946 }
75685a94 947
84281c31 948 {
4f890a30 949 my $message = 'package $i inside (?{ }), ' .
84281c31
A
950 'saved substrings and changing $_';
951 our @a = qw [foo bar];
952 our @b = ();
953 s/(\w)(?{push @b, $1})/,$1,/g for @a;
4f890a30
NC
954 is("@b", "f o o b a r", $message);
955 is("@a", ",f,,o,,o, ,b,,a,,r,", $message);
84281c31 956
4f890a30 957 $message = 'lexical $i inside (?{ }), ' .
84281c31
A
958 'saved substrings and changing $_';
959 no warnings 'closure';
960 my @c = qw [foo bar];
961 my @d = ();
962 s/(\w)(?{push @d, $1})/,$1,/g for @c;
4f890a30
NC
963 is("@d", "f o o b a r", $message);
964 is("@c", ",f,,o,,o, ,b,,a,,r,", $message);
d9f424b2
JH
965 }
966
84281c31 967 {
4f890a30 968 my $message = 'Brackets';
84281c31
A
969 our $brackets;
970 $brackets = qr {
971 { (?> [^{}]+ | (??{ $brackets }) )* }
972 }x;
973
4f890a30
NC
974 ok("{{}" =~ $brackets, $message);
975 is($&, "{}", $message);
976 ok("something { long { and } hairy" =~ $brackets, $message);
977 is($&, "{ and }", $message);
978 ok("something { long { and } hairy" =~ m/((??{ $brackets }))/, $message);
979 is($&, "{ and }", $message);
84281c31 980 }
a4c04bdc 981
84281c31
A
982 {
983 $_ = "a-a\nxbb";
984 pos = 1;
b33825c4 985 ok(!m/^-.*bb/mg, '$_ = "a-a\nxbb"; m/^-.*bb/mg');
84281c31 986 }
a4c04bdc 987
84281c31 988 {
4f890a30 989 my $message = '\G anchor checks';
84281c31
A
990 my $text = "aaXbXcc";
991 pos ($text) = 0;
4f890a30 992 ok($text !~ /\GXb*X/g, $message);
84281c31 993 }
a4c04bdc 994
84281c31
A
995 {
996 $_ = "xA\n" x 500;
b33825c4 997 unlike($_, qr/^\s*A/m, '$_ = "xA\n" x 500; /^\s*A/m"');
a4c04bdc 998
84281c31
A
999 my $text = "abc dbf";
1000 my @res = ($text =~ /.*?(b).*?\b/g);
de26e0cc 1001 is("@res", "b b", '\b is not special');
987aaf07 1002 }
a4c04bdc 1003
84281c31 1004 {
4f890a30 1005 my $message = '\S, [\S], \s, [\s]';
84281c31 1006 my @a = map chr, 0 .. 255;
9d45b377
YO
1007 my @b = grep m/\S/, @a;
1008 my @c = grep m/[^\s]/, @a;
4f890a30 1009 is("@b", "@c", $message);
84281c31
A
1010
1011 @b = grep /\S/, @a;
1012 @c = grep /[\S]/, @a;
4f890a30 1013 is("@b", "@c", $message);
84281c31
A
1014
1015 @b = grep /\s/, @a;
1016 @c = grep /[^\S]/, @a;
4f890a30 1017 is("@b", "@c", $message);
84281c31
A
1018
1019 @b = grep /\s/, @a;
1020 @c = grep /[\s]/, @a;
4f890a30 1021 is("@b", "@c", $message);
72e868c8
KW
1022
1023 # Test an inverted posix class with a char also in the class.
1024 my $nbsp = chr utf8::unicode_to_native(0xA0);
1025 my $non_s = chr utf8::unicode_to_native(0xA1);
1026 my $pat_string = "[^\\S ]";
1027 unlike(" ", qr/$pat_string/, "Verify ' ' !~ /$pat_string/");
1028 like("\t", qr/$pat_string/, "Verify '\\t =~ /$pat_string/");
1029 unlike($nbsp, qr/$pat_string/, "Verify non-utf8-NBSP !~ /$pat_string/");
1030 utf8::upgrade($nbsp);
1031 like($nbsp, qr/$pat_string/, "Verify utf8-NBSP =~ /$pat_string/");
1032 unlike($non_s, qr/$pat_string/, "Verify non-utf8-inverted-bang !~ /$pat_string/");
1033 utf8::upgrade($non_s);
1034 unlike($non_s, qr/$pat_string/, "Verify utf8-inverted-bang !~ /$pat_string/");
84281c31
A
1035 }
1036 {
4f890a30 1037 my $message = '\D, [\D], \d, [\d]';
84281c31
A
1038 my @a = map chr, 0 .. 255;
1039 my @b = grep /\D/, @a;
1040 my @c = grep /[^\d]/, @a;
4f890a30 1041 is("@b", "@c", $message);
84281c31
A
1042
1043 @b = grep /\D/, @a;
1044 @c = grep /[\D]/, @a;
4f890a30 1045 is("@b", "@c", $message);
84281c31
A
1046
1047 @b = grep /\d/, @a;
1048 @c = grep /[^\D]/, @a;
4f890a30 1049 is("@b", "@c", $message);
84281c31
A
1050
1051 @b = grep /\d/, @a;
1052 @c = grep /[\d]/, @a;
4f890a30 1053 is("@b", "@c", $message);
84281c31
A
1054 }
1055 {
4f890a30 1056 my $message = '\W, [\W], \w, [\w]';
84281c31
A
1057 my @a = map chr, 0 .. 255;
1058 my @b = grep /\W/, @a;
1059 my @c = grep /[^\w]/, @a;
4f890a30 1060 is("@b", "@c", $message);
84281c31
A
1061
1062 @b = grep /\W/, @a;
1063 @c = grep /[\W]/, @a;
4f890a30 1064 is("@b", "@c", $message);
84281c31
A
1065
1066 @b = grep /\w/, @a;
1067 @c = grep /[^\W]/, @a;
4f890a30 1068 is("@b", "@c", $message);
84281c31
A
1069
1070 @b = grep /\w/, @a;
1071 @c = grep /[\w]/, @a;
4f890a30 1072 is("@b", "@c", $message);
84281c31 1073 }
a4c04bdc 1074
84281c31
A
1075 {
1076 # see if backtracking optimization works correctly
4f890a30
NC
1077 my $message = 'Backtrack optimization';
1078 like("\n\n", qr/\n $ \n/x, $message);
1079 like("\n\n", qr/\n* $ \n/x, $message);
1080 like("\n\n", qr/\n+ $ \n/x, $message);
1081 like("\n\n", qr/\n? $ \n/x, $message);
1082 like("\n\n", qr/\n*? $ \n/x, $message);
1083 like("\n\n", qr/\n+? $ \n/x, $message);
1084 like("\n\n", qr/\n?? $ \n/x, $message);
1085 unlike("\n\n", qr/\n*+ $ \n/x, $message);
1086 unlike("\n\n", qr/\n++ $ \n/x, $message);
1087 like("\n\n", qr/\n?+ $ \n/x, $message);
84281c31 1088 }
a4c04bdc 1089
84281c31
A
1090 {
1091 package S;
1092 use overload '""' => sub {'Object S'};
1093 sub new {bless []}
0f289c68 1094
4f890a30 1095 my $message = "Ref stringification";
5895685f
NC
1096 ::ok(do { \my $v} =~ /^SCALAR/, "Scalar ref stringification") or diag($message);
1097 ::ok(do {\\my $v} =~ /^REF/, "Ref ref stringification") or diag($message);
1098 ::ok([] =~ /^ARRAY/, "Array ref stringification") or diag($message);
1099 ::ok({} =~ /^HASH/, "Hash ref stringification") or diag($message);
1100 ::ok('S' -> new =~ /^Object S/, "Object stringification") or diag($message);
84281c31 1101 }
a4c04bdc 1102
84281c31 1103 {
4f890a30
NC
1104 my $message = "Test result of match used as match";
1105 ok('a1b' =~ ('xyz' =~ /y/), $message);
1106 is($`, 'a', $message);
1107 ok('a1b' =~ ('xyz' =~ /t/), $message);
1108 is($`, 'a', $message);
84281c31 1109 }
a4c04bdc 1110
84281c31 1111 {
d728c370 1112 my $message = '"1" is not \s';
c11a8df3
NC
1113 warning_is(sub {unlike("1\n" x 102, qr/^\s*\n/m, $message)},
1114 undef, "$message (did not warn)");
84281c31 1115 }
a4c04bdc 1116
84281c31 1117 {
4f890a30 1118 my $message = '\s, [[:space:]] and [[:blank:]]';
84281c31
A
1119 my %space = (spc => " ",
1120 tab => "\t",
1121 cr => "\r",
1122 lf => "\n",
1123 ff => "\f",
1124 # There's no \v but the vertical tabulator seems miraculously
1125 # be 11 both in ASCII and EBCDIC.
1126 vt => chr(11),
1127 false => "space");
1128
1129 my @space0 = sort grep {$space {$_} =~ /\s/ } keys %space;
1130 my @space1 = sort grep {$space {$_} =~ /[[:space:]]/} keys %space;
1131 my @space2 = sort grep {$space {$_} =~ /[[:blank:]]/} keys %space;
1132
075b9d7d 1133 is("@space0", "cr ff lf spc tab vt", $message);
4f890a30
NC
1134 is("@space1", "cr ff lf spc tab vt", $message);
1135 is("@space2", "spc tab", $message);
84281c31 1136 }
a4c04bdc 1137
ff3f963a 1138 {
c9415951 1139 my $n= 50;
93f09d7b 1140 # this must be a high number and go from 0 to N, as the bug we are looking for doesn't
c9415951
YO
1141 # seem to be predictable. Slight changes to the test make it fail earlier or later.
1142 foreach my $i (0 .. $n)
1143 {
1144 my $str= "\n" x $i;
93f09d7b 1145 ok $str=~/.*\z/, "implicit MBOL check string disable does not break things length=$i";
c9415951
YO
1146 }
1147 }
92f3d482
YO
1148 {
1149 # we are actually testing that we dont die when executing these patterns
1150 use utf8;
1151 my $e = "Böck";
1152 ok(utf8::is_utf8($e),"got a unicode string - rt75680");
1153
1154 ok($e !~ m/.*?[x]$/, "unicode string against /.*?[x]\$/ - rt75680");
1155 ok($e !~ m/.*?\p{Space}$/i, "unicode string against /.*?\\p{space}\$/i - rt75680");
1156 ok($e !~ m/.*?[xyz]$/, "unicode string against /.*?[xyz]\$/ - rt75680");
1157 ok($e !~ m/(.*?)[,\p{isSpace}]+((?:\p{isAlpha}[\p{isSpace}\.]{1,2})+)\p{isSpace}*$/, "unicode string against big pattern - rt75680");
1158 }
1159 {
1160 # we are actually testing that we dont die when executing these patterns
6d937e95 1161 my $e = "B" . uni_to_native("\x{f6}") . "ck";
92f3d482
YO
1162 ok(!utf8::is_utf8($e), "got a latin string - rt75680");
1163
1164 ok($e !~ m/.*?[x]$/, "latin string against /.*?[x]\$/ - rt75680");
1165 ok($e !~ m/.*?\p{Space}$/i, "latin string against /.*?\\p{space}\$/i - rt75680");
1166 ok($e !~ m/.*?[xyz]$/,"latin string against /.*?[xyz]\$/ - rt75680");
1167 ok($e !~ m/(.*?)[,\p{isSpace}]+((?:\p{isAlpha}[\p{isSpace}\.]{1,2})+)\p{isSpace}*$/,"latin string against big pattern - rt75680");
1168 }
c920e018
A
1169
1170 {
1171 #
1172 # Tests for bug 77414.
1173 #
1174
4f890a30 1175 my $message = '\p property after empty * match';
c920e018 1176 {
4f890a30
NC
1177 like("1", qr/\s*\pN/, $message);
1178 like("-", qr/\s*\p{Dash}/, $message);
1179 like(" ", qr/\w*\p{Blank}/, $message);
c920e018
A
1180 }
1181
4f890a30
NC
1182 like("1", qr/\s*\pN+/, $message);
1183 like("-", qr/\s*\p{Dash}{1}/, $message);
1184 like(" ", qr/\w*\p{Blank}{1,4}/, $message);
c920e018
A
1185
1186 }
1187
6d937e95
KW
1188 { # Some constructs with Latin1 characters cause a utf8 string not
1189 # to match itself in non-utf8
1190 my $c = uni_to_native("\xc0");
1191 my $pattern = my $utf8_pattern = qr/(($c)+,?)/;
634c83a2
KW
1192 utf8::upgrade($utf8_pattern);
1193 ok $c =~ $pattern, "\\xc0 =~ $pattern; Neither pattern nor target utf8";
d4e0b827 1194 ok $c =~ /$pattern/i, "\\xc0 =~ /$pattern/i; Neither pattern nor target utf8";
634c83a2 1195 ok $c =~ $utf8_pattern, "\\xc0 =~ $pattern; pattern utf8, target not";
d4e0b827 1196 ok $c =~ /$utf8_pattern/i, "\\xc0 =~ /$pattern/i; pattern utf8, target not";
634c83a2
KW
1197 utf8::upgrade($c);
1198 ok $c =~ $pattern, "\\xc0 =~ $pattern; target utf8, pattern not";
d4e0b827 1199 ok $c =~ /$pattern/i, "\\xc0 =~ /$pattern/i; target utf8, pattern not";
634c83a2 1200 ok $c =~ $utf8_pattern, "\\xc0 =~ $pattern; Both target and pattern utf8";
d4e0b827 1201 ok $c =~ /$utf8_pattern/i, "\\xc0 =~ /$pattern/i; Both target and pattern utf8";
634c83a2
KW
1202 }
1203
6d937e95 1204 { # Make sure can override the formatting
8cc86590 1205 use feature 'unicode_strings';
6d937e95
KW
1206 ok uni_to_native("\xc0") =~ /\w/, 'Under unicode_strings: "\xc0" =~ /\w/';
1207 ok uni_to_native("\xc0") !~ /(?d:\w)/, 'Under unicode_strings: "\xc0" !~ /(?d:\w)/';
8cc86590
KW
1208 }
1209
704f71be 1210 {
5b6010b3
YO
1211 my $str= "\x{100}";
1212 chop $str;
1213 my $qr= qr/$str/;
de26e0cc 1214 is("$qr", "(?^:)", "Empty pattern qr// stringifies to (?^:) with unicode flag enabled - Bug #80212");
5b6010b3
YO
1215 $str= "";
1216 $qr= qr/$str/;
de26e0cc 1217 is("$qr", "(?^:)", "Empty pattern qr// stringifies to (?^:) with unicode flag disabled - Bug #80212");
5b6010b3
YO
1218
1219 }
1220
72aa120d 1221 {
04934b6d 1222 local $::TODO = "[perl #38133]";
72aa120d
KW
1223
1224 "A" =~ /(((?:A))?)+/;
1225 my $first = $2;
1226
1227 "A" =~ /(((A))?)+/;
1228 my $second = $2;
1229
de26e0cc 1230 is($first, $second);
72aa120d
KW
1231 }
1232
99ca48e1
DM
1233 {
1234 # RT #3516: \G in a m//g expression causes problems
1235 my $count = 0;
1236 while ("abc" =~ m/(\G[ac])?/g) {
1237 last if $count++ > 10;
1238 }
1239 ok($count < 10, 'RT #3516 A');
1240
1241 $count = 0;
1242 while ("abc" =~ m/(\G|.)[ac]/g) {
1243 last if $count++ > 10;
1244 }
1245 ok($count < 10, 'RT #3516 B');
1246
1247 $count = 0;
1248 while ("abc" =~ m/(\G?[ac])?/g) {
1249 last if $count++ > 10;
1250 }
1251 ok($count < 10, 'RT #3516 C');
1252 }
d774cd11
YO
1253 {
1254 # RT #84294: Is this a bug in the simple Perl regex?
1255 # : Nested buffers and (?{...}) dont play nicely on partial matches
1256 our @got= ();
1257 ok("ab" =~ /((\w+)(?{ push @got, $2 })){2}/,"RT #84294: Pattern should match");
d774cd11
YO
1258 my $want= "'ab', 'a', 'b'";
1259 my $got= join(", ", map { defined($_) ? "'$_'" : "undef" } @got);
1260 is($got,$want,'RT #84294: check that "ab" =~ /((\w+)(?{ push @got, $2 })){2}/ leaves @got in the correct state');
1261 }
1262
0bda3001
KW
1263 {
1264 # Suppress warnings, as the non-unicode one comes out even if turn off
1265 # warnings here (because the execution is done in another scope).
1266 local $SIG{__WARN__} = sub {};
1267 my $str = "\x{110000}";
1268
2d88a86a
KW
1269 unlike($str, qr/\p{ASCII_Hex_Digit=True}/, "Non-Unicode doesn't match \\p{AHEX=True}");
1270 like($str, qr/\p{ASCII_Hex_Digit=False}/, "Non-Unicode matches \\p{AHEX=False}");
1271 like($str, qr/\P{ASCII_Hex_Digit=True}/, "Non-Unicode matches \\P{AHEX=True}");
1272 unlike($str, qr/\P{ASCII_Hex_Digit=False}/, "Non-Unicode matches \\P{AHEX=FALSE}");
0bda3001
KW
1273 }
1274
b289b443 1275 {
c256547e 1276 # Test that IDstart works, but because the author (khw) knows
b289b443
KW
1277 # regexes much better than the rest of the core, it is being done here
1278 # in the context of a regex which relies on buffer names beginng with
1279 # IDStarts.
1280 use utf8;
1281 my $str = "abc";
1282 like($str, qr/(?<a>abc)/, "'a' is legal IDStart");
1283 like($str, qr/(?<_>abc)/, "'_' is legal IDStart");
1284 like($str, qr/(?<ß>abc)/, "U+00DF is legal IDStart");
1285 like($str, qr/(?<ℕ>abc)/, "U+2115' is legal IDStart");
1286
1287 # This test works on Unicode 6.0 in which U+2118 and U+212E are legal
1288 # IDStarts there, but are not Word characters, and therefore Perl
1289 # doesn't allow them to be IDStarts. But there is no guarantee that
1290 # Unicode won't change things around in the future so that at some
1291 # future Unicode revision these tests would need to be revised.
1292 foreach my $char ("%", "×", chr(0x2118), chr(0x212E)) {
1293 my $prog = <<"EOP";
1294use utf8;;
1295"abc" =~ qr/(?<$char>abc)/;
1296EOP
1297 utf8::encode($prog);
20e5bab4 1298 fresh_perl_like($prog, qr!Group name must start with a non-digit word character!, {},
b289b443
KW
1299 sprintf("'U+%04X not legal IDFirst'", ord($char)));
1300 }
1301 }
bbdd8bad
KW
1302
1303 { # [perl #101710]
1304 my $pat = "b";
1305 utf8::upgrade($pat);
1306 like("\xffb", qr/$pat/i, "/i: utf8 pattern, non-utf8 string, latin1-char preceding matching char in string");
1307 }
1308
ba510004
FC
1309 { # Crash with @a =~ // warning
1310 local $SIG{__WARN__} = sub {
1311 pass 'no crash for @a =~ // warning'
1312 };
1313 eval ' sub { my @a =~ // } ';
1314 }
1315
cc88c9aa
FC
1316 { # Concat overloading and qr// thingies
1317 my @refs;
1318 my $qr = qr//;
3bbc3d30
YO
1319 package Cat {
1320 require overload;
1321 overload->import(
cc88c9aa
FC
1322 '""' => sub { ${$_[0]} },
1323 '.' => sub {
1324 push @refs, ref $_[1] if ref $_[1];
1325 bless $_[2] ? \"$_[1]${$_[0]}" : \"${$_[0]}$_[1]"
1326 }
3bbc3d30 1327 );
cc88c9aa
FC
1328 }
1329 my $s = "foo";
1330 my $o = bless \$s, Cat::;
1331 /$o$qr/;
1332 is "@refs", "Regexp", '/$o$qr/ passes qr ref to cat overload meth';
1333 }
1334
21eede78
YO
1335 {
1336 my $count=0;
1337 my $str="\n";
1338 $count++ while $str=~/.*/g;
1339 is $count, 2, 'test that ANCH_MBOL works properly. We should get 2 from $count++ while "\n"=~/.*/g';
1340 my $class_count= 0;
1341 $class_count++ while $str=~/[^\n]*/g;
1342 is $class_count, $count, 'while "\n"=~/.*/g and while "\n"=~/[^\n]*/g should behave the same';
1343 my $anch_count= 0;
1344 $anch_count++ while $str=~/^.*/mg;
1345 is $anch_count, 1, 'while "\n"=~/^.*/mg should match only once';
1346 }
96f54887
KW
1347
1348 { # [perl #111174]
1349 use re '/u';
6d937e95
KW
1350 my $A_grave = uni_to_native("\xc0");
1351 like uni_to_native("\xe0"), qr/(?i:$A_grave)/, "(?i: shouldn't lose the passed in /u";
96f54887
KW
1352 use re '/a';
1353 unlike "\x{100}", qr/(?i:\w)/, "(?i: shouldn't lose the passed in /a";
1354 use re '/aa';
1355 unlike 'k', qr/(?i:\N{KELVIN SIGN})/, "(?i: shouldn't lose the passed in /aa";
945961fd 1356 unlike 'k', qr'(?i:\N{KELVIN SIGN})', "(?i: shouldn't lose the passed in /aa";
96f54887 1357 }
6ae44cd2
DM
1358
1359 {
1360 # the test for whether the pattern should be re-compiled should
1361 # consider the UTF8ness of the previous and current pattern
1362 # string, as well as the physical bytes of the pattern string
1363
6d937e95 1364 for my $s (byte_utf8a_to_utf8n("\xc4\x80"), "\x{100}") {
6ae44cd2
DM
1365 ok($s =~ /^$s$/, "re-compile check is UTF8-aware");
1366 }
1367 }
1368
e03b874a
DM
1369 # #113682 more overloading and qr//
1370 # when doing /foo$overloaded/, if $overloaded returns
1371 # a qr/(?{})/ via qr or "" overloading, then 'use re 'eval'
1372 # shouldn't be required. Via '.', it still is.
1373 {
1374 package Qr0;
1375 use overload 'qr' => sub { qr/(??{50})/ };
1376
1377 package Qr1;
1378 use overload '""' => sub { qr/(??{51})/ };
1379
1380 package Qr2;
1381 use overload '.' => sub { $_[1] . qr/(??{52})/ };
1382
1383 package Qr3;
1384 use overload '""' => sub { qr/(??{7})/ },
1385 '.' => sub { $_[1] . qr/(??{53})/ };
1386
1387 package Qr_indirect;
1388 use overload '""' => sub { $_[0][0] };
1389
1390 package main;
1391
1392 for my $i (0..3) {
1393 my $o = bless [], "Qr$i";
1394 if ((0,0,1,1)[$i]) {
1395 eval { "A5$i" =~ /^A$o$/ };
1396 like($@, qr/Eval-group not allowed/, "Qr$i");
1397 eval { "5$i" =~ /$o/ };
1398 like($@, ($i == 3 ? qr/^$/ : qr/no method found,/),
1399 "Qr$i bare");
1400 {
1401 use re 'eval';
1402 ok("A5$i" =~ /^A$o$/, "Qr$i - with use re eval");
1403 eval { "5$i" =~ /$o/ };
1404 like($@, ($i == 3 ? qr/^$/ : qr/no method found,/),
1405 "Qr$i bare - with use re eval");
1406 }
1407 }
1408 else {
1409 ok("A5$i" =~ /^A$o$/, "Qr$i");
1410 ok("5$i" =~ /$o/, "Qr$i bare");
1411 }
1412 }
1413
1414 my $o = bless [ bless [], "Qr1" ], 'Qr_indirect';
1415 ok("A51" =~ /^A$o/, "Qr_indirect");
1416 ok("51" =~ /$o/, "Qr_indirect bare");
1417 }
1418
34b39fc9
KW
1419 { # Various flags weren't being set when a [] is optimized into an
1420 # EXACTish node
6d937e95 1421 ok("\x{017F}\x{017F}" =~ qr/^[$sharp_s]?$/i, "[] to EXACTish optimization");
34b39fc9
KW
1422 }
1423
3ae8ec47
KW
1424 { # Test that it avoids spllitting a multi-char fold across nodes
1425 my $utf8_locale = find_utf8_ctype_locale();
1426 for my $char('F', $sharp_s, "\x{FB00}") {
1427 my $length = 260; # Long enough to overflow an EXACTFish regnode
1428 my $p = $char x $length;
1429 my $s = ($char eq $sharp_s) ? 'ss' : 'ff';
1430 $s = $s x $length;
1431 for my $charset (qw(u d l aa)) {
1432 for my $utf8 (0..1) {
1433 SKIP:
1434 for my $locale ('C', $utf8_locale) {
1435 skip "test skipped for non-C locales", 2
1436 if $charset ne 'l'
1437 && (! defined $locale || $locale ne 'C');
1438 if ($charset eq 'l') {
1439 if (! defined $locale) {
1440 skip "No UTF-8 locale", 2;
1441 }
1442
1443 use POSIX;
1444 POSIX::setlocale(&LC_CTYPE, $locale);
1445 }
1446
1447 my $pat = $p;
1448 utf8::upgrade($pat) if $utf8;
1449 my $should_pass =
1450 ( $charset eq 'u'
1451 || ($charset eq 'd' && $utf8)
1452 || ($charset eq 'd' && ( $char =~ /[[:ascii:]]/
1453 || ord $char > 255))
1454 || ($charset eq 'aa' && $char =~ /[[:ascii:]]/)
1455 || ($charset eq 'l' && $locale ne 'C')
1456 || ($charset eq 'l' && $char =~ /[[:ascii:]]/)
1457 );
1458 my $name = "(?i$charset), utf8=$utf8, locale=$locale,"
1459 . " char=" . sprintf "%x", ord $char;
1460 no warnings 'locale';
1461 is (eval " '$s' =~ qr/(?i$charset)$pat/;",
1462 $should_pass, $name);
1463 fail "$name: $@" if $@;
1464 is (eval " 'a$s' =~ qr/(?i$charset)a$pat/;",
1465 $should_pass, "extra a, $name");
1466 fail "$name: $@" if $@;
1467 }
1468 }
1469 }
1470 }
1471 }
1472
5e4a1da1 1473 {
6d937e95 1474 for my $char (":", uni_to_native("\x{f7}"), "\x{2010}") {
5e4a1da1
KW
1475 my $utf8_char = $char;
1476 utf8::upgrade($utf8_char);
1477 my $display = $char;
1478 $display = display($display);
1479 my $utf8_display = "utf8::upgrade(\"$display\")";
1480
1481 like($char, qr/^$char?$/, "\"$display\" =~ /^$display?\$/");
1482 like($char, qr/^$utf8_char?$/, "my \$p = \"$display\"; utf8::upgrade(\$p); \"$display\" =~ /^\$p?\$/");
1483 like($utf8_char, qr/^$char?$/, "my \$c = \"$display\"; utf8::upgrade(\$c); \"\$c\" =~ /^$display?\$/");
1484 like($utf8_char, qr/^$utf8_char?$/, "my \$c = \"$display\"; utf8::upgrade(\$c); my \$p = \"$display\"; utf8::upgrade(\$p); \"\$c\" =~ /^\$p?\$/");
1485 }
1486 }
1487
4fab19ce
DM
1488 {
1489 # #116148: Pattern utf8ness sticks around globally
1490 # the utf8 in the first match was sticking around for the second
1491 # match
1492
1493 use feature 'unicode_strings';
1494
1495 my $x = "\x{263a}";
1496 $x =~ /$x/;
1497
1498 my $text = "Perl";
1499 ok("Perl" =~ /P.*$/i, '#116148');
1500 }
1501
b8372399
DIM
1502 { # 118297: Mixing up- and down-graded strings in regex
1503 utf8::upgrade(my $u = "\x{e5}");
1504 utf8::downgrade(my $d = "\x{e5}");
1505 my $warned;
1506 local $SIG{__WARN__} = sub { $warned++ if $_[0] =~ /\AMalformed UTF-8/ };
1507 my $re = qr/$u$d/;
1508 ok(!$warned, "no warnings when interpolating mixed up-/downgraded strings in pattern");
1509 my $c = "\x{e5}\x{e5}";
1510 utf8::downgrade($c);
1511 like($c, $re, "mixed up-/downgraded pattern matches downgraded string");
1512 utf8::upgrade($c);
1513 like($c, $re, "mixed up-/downgraded pattern matches upgraded string");
1514 }
4fab19ce 1515
f1e1b256
YO
1516 {
1517 # if we have 87 capture buffers defined then \87 should refer to the 87th.
1518 # test that this is true for 1..100
19438407
S
1519 # Note that this test causes the engine to recurse at runtime, and
1520 # hence use a lot of C stack.
6096c8b5
DM
1521
1522 # Compiling for all 100 nested captures blows the stack under
1523 # clang and ASan; reduce.
1524 my $max_captures = $Config{ccflags} =~ /sanitize/ ? 20 : 100;
1525
f1e1b256 1526 for my $i (1..100) {
6096c8b5
DM
1527 if ($i > $max_captures) {
1528 pass("skipping $i buffers under ASan aa");
1529 pass("skipping $i buffers under ASan aba");
1530 next;
1531 }
31108f3e
YO
1532 my $capture= "a";
1533 $capture= "($capture)" for 1 .. $i;
1534 for my $mid ("","b") {
1535 my $str= "a${mid}a";
1536 my $backref= "\\$i";
1537 eval {
1538 ok($str=~/$capture$mid$backref/,"\\$i works with $i buffers '$str'=~/...$mid$backref/");
1539 1;
1540 } or do {
1541 is("$@","","\\$i works with $i buffers works with $i buffers '$str'=~/...$mid$backref/");
1542 };
1543 }
f1e1b256
YO
1544 }
1545 }
1546
5411a0e5
DM
1547 # this mixture of readonly (not COWable) and COWable strings
1548 # messed up the capture buffers under COW. The actual test results
1549 # are incidental; the issue is was an AddressSanitizer failure
1550 {
1551 my $c ='AB';
1552 my $res = '';
1553 for ($c, 'C', $c, 'DE') {
1554 ok(/(.)/, "COWable match");
1555 $res .= $1;
1556 }
1557 is($res, "ACAD");
1558 }
1559
1560
61965f1d
FC
1561 {
1562 # RT #45667
1563 # /[#$x]/x didn't interpolate the var $x.
1564 my $b = 'cd';
1565 my $s = 'abcd$%#&';
1566 $s =~ s/[a#$b%]/X/g;
1567 is ($s, 'XbXX$XX&', 'RT #45667 without /x');
1568 $s = 'abcd$%#&';
1569 $s =~ s/[a#$b%]/X/gx;
1570 is ($s, 'XbXX$XX&', 'RT #45667 with /x');
1571 }
1572
0cb43d32
FC
1573 {
1574 no warnings "uninitialized";
1575 my @a;
1576 $a[1]++;
1577 /@a/;
1578 pass('no crash with /@a/ when array has nonexistent elems');
1579 }
1580
475b1e90
FC
1581 {
1582 is runperl(prog => 'delete $::{qq-\cR-}; //; print qq-ok\n-'),
1583 "ok\n",
4a2b275c 1584 'deleting *^R does not result in crashes';
d772ce1c 1585 no warnings 'once';
4a2b275c
FC
1586 *^R = *caretRglobwithnoscalar;
1587 "" =~ /(?{42})/;
1588 is $^R, 42, 'assigning to *^R does not result in a crash';
7e68f152
FC
1589 is runperl(
1590 stderr => 1,
1591 prog => 'eval q|'
1592 .' q-..- =~ /(??{undef *^R;q--})(?{42})/; '
1593 .' print qq-$^R\n-'
1594 .'|'
1595 ),
1596 "42\n",
1597 'undefining *^R within (??{}) does not result in a crash';
475b1e90
FC
1598 }
1599
8498497f
KW
1600 SKIP: { # Test literal range end point special handling
1601 unless ($::IS_EBCDIC) {
423df6e4 1602 skip "Valid only for EBCDIC", 24;
8498497f
KW
1603 }
1604
1605 like("\x89", qr/[i-j]/, '"\x89" should match [i-j]');
1606 unlike("\x8A", qr/[i-j]/, '"\x8A" shouldnt match [i-j]');
1607 unlike("\x90", qr/[i-j]/, '"\x90" shouldnt match [i-j]');
1608 like("\x91", qr/[i-j]/, '"\x91" should match [i-j]');
1609
423df6e4
KW
1610 like("\x89", qr/[i-\N{LATIN SMALL LETTER J}]/, '"\x89" should match [i-\N{LATIN SMALL LETTER J}]');
1611 unlike("\x8A", qr/[i-\N{LATIN SMALL LETTER J}]/, '"\x8A" shouldnt match [i-\N{LATIN SMALL LETTER J}]');
1612 unlike("\x90", qr/[i-\N{LATIN SMALL LETTER J}]/, '"\x90" shouldnt match [i-\N{LATIN SMALL LETTER J}]');
1613 like("\x91", qr/[i-\N{LATIN SMALL LETTER J}]/, '"\x91" should match [i-\N{LATIN SMALL LETTER J}]');
1614
1615 like("\x89", qr/[i-\N{U+6A}]/, '"\x89" should match [i-\N{U+6A}]');
1616 unlike("\x8A", qr/[i-\N{U+6A}]/, '"\x8A" shouldnt match [i-\N{U+6A}]');
1617 unlike("\x90", qr/[i-\N{U+6A}]/, '"\x90" shouldnt match [i-\N{U+6A}]');
1618 like("\x91", qr/[i-\N{U+6A}]/, '"\x91" should match [i-\N{U+6A}]');
1619
1620 like("\x89", qr/[\N{U+69}-\N{U+6A}]/, '"\x89" should match [\N{U+69}-\N{U+6A}]');
1621 unlike("\x8A", qr/[\N{U+69}-\N{U+6A}]/, '"\x8A" shouldnt match [\N{U+69}-\N{U+6A}]');
1622 unlike("\x90", qr/[\N{U+69}-\N{U+6A}]/, '"\x90" shouldnt match [\N{U+69}-\N{U+6A}]');
1623 like("\x91", qr/[\N{U+69}-\N{U+6A}]/, '"\x91" should match [\N{U+69}-\N{U+6A}]');
1624
8498497f
KW
1625 like("\x89", qr/[i-\x{91}]/, '"\x89" should match [i-\x{91}]');
1626 like("\x8A", qr/[i-\x{91}]/, '"\x8A" should match [i-\x{91}]');
1627 like("\x90", qr/[i-\x{91}]/, '"\x90" should match [i-\x{91}]');
1628 like("\x91", qr/[i-\x{91}]/, '"\x91" should match [i-\x{91}]');
1629
1630 # Need to use eval, because tries to compile on ASCII platforms even
1631 # though the tests are skipped, and fails because 0x89-j is an illegal
1632 # range there.
6d937e95
KW
1633 like("\x89", eval 'qr/[\x{89}-j]/', '"\x89" should match [\x{89}-j]');
1634 like("\x8A", eval 'qr/[\x{89}-j]/', '"\x8A" should match [\x{89}-j]');
1635 like("\x90", eval 'qr/[\x{89}-j]/', '"\x90" should match [\x{89}-j]');
1636 like("\x91", eval 'qr/[\x{89}-j]/', '"\x91" should match [\x{89}-j]');
8498497f 1637 }
d6ef1678 1638
749e076f
KW
1639 # These are based on looking at the code in regcomp.c
1640 # We don't look for specific code, just the existence of an SSC
1641 foreach my $re (qw( qr/a?c/
1642 qr/a?c/i
1643 qr/[ab]?c/
1644 qr/\R?c/
1645 qr/\d?c/d
1646 qr/\w?c/l
1647 qr/\s?c/a
b35552de 1648 qr/[[:lower:]]?c/u
749e076f 1649 )) {
d7919c41
FC
1650 SKIP: {
1651 skip "no re-debug under miniperl" if is_miniperl;
749e076f
KW
1652 my $prog = <<"EOP";
1653use re qw(Debug COMPILE);
1654$re;
1655EOP
20e5bab4 1656 fresh_perl_like($prog, qr/synthetic stclass/, { stderr=>1 }, "$re generates a synthetic start class");
d7919c41 1657 }
749e076f
KW
1658 }
1659
86897aa6
KW
1660 {
1661 like "\x{AA}", qr/a?[\W_]/d, "\\W with /d synthetic start class works";
1662 }
1663
6d937e95
KW
1664 SKIP: {
1665 skip("Tests are ASCII-centric, some would fail on EBCDIC", 12) if $::IS_EBCDIC;
1666
e8ea8356
JH
1667 # Verify that the very last Latin-1 U+00FF
1668 # (LATIN SMALL LETTER Y WITH DIAERESIS)
1669 # and its UPPER counterpart (U+0178 which is pure Unicode),
1670 # and likewise for the very first pure Unicode
1671 # (LATIN CAPITAL LETTER A WITH MACRON) fold-match properly,
1672 # and there are no off-by-one logic errors in the transition zone.
1673
1674 ok("\xFF" =~ /\xFF/i, "Y WITH DIAERESIS l =~ l");
1675 ok("\xFF" =~ /\x{178}/i, "Y WITH DIAERESIS l =~ u");
1676 ok("\x{178}" =~ /\xFF/i, "Y WITH DIAERESIS u =~ l");
1677 ok("\x{178}" =~ /\x{178}/i, "Y WITH DIAERESIS u =~ u");
86897aa6 1678
e8ea8356
JH
1679 # U+00FF with U+05D0 (non-casing Hebrew letter).
1680 ok("\xFF\x{5D0}" =~ /\xFF\x{5D0}/i, "Y WITH DIAERESIS l =~ l");
1681 ok("\xFF\x{5D0}" =~ /\x{178}\x{5D0}/i, "Y WITH DIAERESIS l =~ u");
1682 ok("\x{178}\x{5D0}" =~ /\xFF\x{5D0}/i, "Y WITH DIAERESIS u =~ l");
1683 ok("\x{178}\x{5D0}" =~ /\x{178}\x{5D0}/i, "Y WITH DIAERESIS u =~ u");
1684
1685 # U+0100.
1686 ok("\x{100}" =~ /\x{100}/i, "A WITH MACRON u =~ u");
1687 ok("\x{100}" =~ /\x{101}/i, "A WITH MACRON u =~ l");
1688 ok("\x{101}" =~ /\x{100}/i, "A WITH MACRON l =~ u");
1689 ok("\x{101}" =~ /\x{101}/i, "A WITH MACRON l =~ l");
1690 }
0b2c2a84 1691
8373491a
KW
1692 {
1693 use utf8;
1694 ok("abc" =~ /a\85b\85c/x, "NEL is white-space under /x");
1695 }
1696
412f55bb
KW
1697 {
1698 ok('a(b)c' =~ qr(a\(b\)c), "'\\(' is a literal in qr(...)");
1699 ok('a[b]c' =~ qr[a\[b\]c], "'\\[' is a literal in qr[...]");
1700 ok('a{3}c' =~ qr{a\{3\}c}, # Only failed when { could be a meta
1701 "'\\{' is a literal in qr{...}, where it could be a quantifier");
1702
1703 # This one is for completeness
1704 ok('a<b>c' =~ qr<a\<b\>c>, "'\\<' is a literal in qr<...>)");
1705 }
1706
b6e093f2
KW
1707 { # Was getting optimized into EXACT (non-folding node)
1708 my $x = qr/[x]/i;
1709 utf8::upgrade($x);
1710 like("X", qr/$x/, "UTF-8 of /[x]/i matches upper case");
1711 }
1712
394d2d3f
KW
1713SKIP: { # make sure we get an error when \p{} cannot load Unicode tables
1714 skip("Unicode tables always now loaded", 1);
fa542f55
FC
1715 fresh_perl_like(<<' prog that cannot load uni tables',
1716 BEGIN {
1717 @INC = '../lib';
1718 require utf8; require 'utf8_heavy.pl';
1719 @INC = ();
1720 }
1721 $name = 'A B';
1722 if ($name =~ /(\p{IsUpper}) (\p{IsUpper})/){
1723 print "It's good! >$1< >$2<\n";
1724 } else {
1725 print "It's not good...\n";
1726 }
1727 prog that cannot load uni tables
1728 qr/^Can't locate unicore\/Heavy\.pl(?x:
1729 )|^Can't find Unicode property definition/,
1730 undef,
1731 '\p{} should not fail silently when uni tables evanesce');
1732 }
59206727
KW
1733
1734 { # Special handling of literal-ended ranges in [...] was breaking this
1735 use utf8;
1736 like("ÿ", qr/[ÿ-ÿ]/, "\"ÿ\" should match [ÿ-ÿ]");
1737 }
405dffcb
KW
1738
1739 { # [perl #123539]
1740 like("TffffffffffffTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT5TTTTTTTTTTTTTTTTTTTTTTTTT3TTgTTTTTTTTTTTTTTTTTTTTT2TTTTTTTTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHiHHHHHHHfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff&ffff", qr/TffffffffffffTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT5TTTTTTTTTTTTTTTTTTTTTTTTT3TTgTTTTTTTTTTTTTTTTTTTTT2TTTTTTTTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHiHHHHHHHfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff&ffff/il, "");
1741 like("TffffffffffffT\x{100}TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT5TTTTTTTTTTTTTTTTTTTTTTTTT3TTgTTTTTTTTTTTTTTTTTTTTT2TTTTTTTTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHiHHHHHHHfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff&ffff", qr/TffffffffffffT\x{100}TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT5TTTTTTTTTTTTTTTTTTTTTTTTT3TTgTTTTTTTTTTTTTTTTTTTTT2TTTTTTTTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHiHHHHHHHfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff&ffff/il, "");
1742 }
1743
56f81afc
HS
1744 { # [perl #123604]
1745 my($s, $x, @x) = ('abc', 'a', 'd');
1746 my $long = 'b' x 2000;
1747 my $eval = q{$s =~ m{$x[bbb]c} ? 1 : 0};
1748 $eval =~ s{bbb}{$long};
1749 my $match = eval $eval;
1750 ok(1, "did not crash");
1751 ok($match, "[bbb...] resolved as character class, not subscript");
1752 }
8a6d8ec6
HS
1753
1754 { # [perl #123755]
1755 for my $pat ('(??', '(?P', '(?i-') {
1756 eval qq{ qr/$pat/ };
1757 ok(1, "qr/$pat/ did not crash");
1758 eval qq{ qr/${pat}\x{123}/ };
1759 my $e = $@;
1760 like($e, qr{\x{123}},
1761 "qr/${pat}x/ shows x in error even if it's a wide character");
1762 }
1763 }
b3725d49
HS
1764
1765 {
1766 # Expect one of these sizes to cause overflow and wrap to negative
1767 for my $bits (32, 64) {
1768 my $wrapneg = 2 ** ($bits - 2) * 3;
1769 for my $sign ('', '-') {
1770 my $pat = sprintf "qr/(?%s%u)/", $sign, $wrapneg;
1771 eval $pat;
1772 ok(1, "big backref $pat did not crash");
1773 }
1774 }
1775 }
65651c16 1776 {
65651c16
YO
1777 # Test that we handle qr/\8888888/ and variants without an infinite loop,
1778 # we use a test within a test so we can todo it, and make sure we don't
1779 # infinite loop our tests.
1780 # NOTE - Do not put quotes in the code!
1781 # NOTE - We have to triple escape the backref in the pattern below.
1782 my $code='
3d7c117d 1783 BEGIN{require q(./test.pl);}
65651c16
YO
1784 watchdog(3);
1785 for my $len (1 .. 20) {
1786 my $eights= q(8) x $len;
1787 eval qq{ qr/\\\\$eights/ };
1788 }
1789 print q(No infinite loop here!);
1790 ';
1791 fresh_perl_is($code, "No infinite loop here!", {},
1792 "test that we handle things like m/\\888888888/ without infinite loops" );
1793 }
4a0c7558 1794
22b433ef
KW
1795 { # Test that we handle some malformed UTF-8 without looping [perl
1796 # #123562]
1797
1798 my $code='
3d7c117d 1799 BEGIN{require q(./test.pl);}
22b433ef 1800 use Encode qw(_utf8_on);
95c6a212
KW
1801 # \x80 and \x41 are continuation bytes in their respective
1802 # character sets
1803 my $malformed = (ord("A") == 65) ? "a\x80\n" : "a\x41\n";
1804 utf8::downgrade($malformed);
22b433ef
KW
1805 _utf8_on($malformed);
1806 watchdog(3);
1807 $malformed =~ /(\n\r|\r)$/;
1808 print q(No infinite loop here!);
1809 ';
1810 fresh_perl_like($code, qr/Malformed UTF-8 character/, {},
1811 "test that we handle some UTF-8 malformations without looping" );
1812 }
1813
4a0c7558
HS
1814 {
1815 # [perl #123843] hits SEGV trying to compile this pattern
1816 my $match;
1817 eval q{ ($match) = ("xxyxxyxy" =~ m{(x+(y(?1))*)}) };
1818 ok(1, "compiled GOSUB in CURLYM ok");
1819 is($match, 'xxyxxyx', "matched GOSUB in CURLYM");
1820 }
e92b41c6
HS
1821
1822 {
1823 # [perl #123852] doesn't avoid all the capture-related work with
1824 # //n, leading to possible memory corruption
1825 eval q{ qr{()(?1)}n };
1826 my $error = $@;
1827 ok(1, "qr{()(?1)}n didn't crash");
1828 like($error, qr{Reference to nonexistent group},
1829 'gave appropriate error for qr{()(?1)}n');
1830 }
9457bb3f
KW
1831
1832 {
1833 # [perl #126406] panic with unmatchable quantifier
1834 my $code='
1835 no warnings "regexp";
1836 "" =~ m/(.0\N{6,0}0\N{6,0}000000000000000000000000000000000)/;
1837 ';
1838 fresh_perl_is($code, "", {},
1839 "perl [#126406] panic");
1840 }
ba6840fb 1841 {
401a8022
YO
1842 my $bug="[perl #126182]"; # test for infinite pattern recursion
1843 for my $tuple (
401a8022
YO
1844 [ 'q(a)=~/(.(?2))((?<=(?=(?1)).))/', "died", "look ahead left recursion fails fast" ],
1845 [ 'q(aa)=~/(?R)a/', "died", "left-recursion fails fast", ],
1846 [ 'q(bbaa)=~/(?&x)(?(DEFINE)(?<x>(?&y)*a)(?<y>(?&x)*b))/',
1847 "died", "inter-cyclic optional left recursion dies" ],
1848 [ 'q(abc) =~ /a((?1)?)c/', "died", "optional left recursion dies" ],
1849 [ 'q(abc) =~ /a((?1)??)c/', "died", "min mod left recursion dies" ],
1850 [ 'q(abc) =~ /a((?1)*)c/', "died", "* left recursion dies" ],
1851 [ 'q(abc) =~ /a((?1)+)c/', "died", "+ left recursion dies" ],
1852 [ 'q(abc) =~ /a((?1){0,3})c/', "died", "{0,3} left recursion fails fast" ],
1853
1854 [ 'q(aaabbb)=~/a(?R)?b/', "matched", "optional self recursion works" ],
ce12e254
YO
1855 [ '"((5maa-maa)(maa-3maa))" =~ /(\\\\((?:[^()]++|(?0))*+\\\\))/', "matched",
1856 "recursion and possessive captures", "((5maa-maa)(maa-3maa))"],
1857 [ '"((5maa-maa)(maa-3maa))" =~ /(\\\\((?:[^()]++|(?1))*+\\\\))/', "matched",
1858 "recursion and possessive captures", "((5maa-maa)(maa-3maa))"],
1859 [ '"((5maa-maa)(maa-3maa))" =~ /(\\\\((?:[^()]+|(?0))*\\\\))/', "matched",
1860 "recursion and possessive captures", "((5maa-maa)(maa-3maa))"],
1861 [ '"((5maa-maa)(maa-3maa))" =~ /(\\\\((?:[^()]+|(?1))*\\\\))/', "matched",
1862 "recursion and possessive captures", "((5maa-maa)(maa-3maa))"],
401a8022 1863 ) {
ce12e254 1864 my ($expr, $expect, $test_name, $cap1)= @$tuple;
401a8022
YO
1865 # avoid quotes in this code!
1866 my $code='
3d7c117d 1867 BEGIN{require q(./test.pl);}
401a8022 1868 watchdog(3);
ce12e254
YO
1869 my $status= eval(q{ !(' . $expr . ') ? q(failed) : ' .
1870 ($cap1 ? '($1 ne q['.$cap1.']) ? qq(badmatch:$1) : ' : '') .
1871 ' q(matched) })
1872 || ( ( $@ =~ /Infinite recursion/ ) ? qq(died) : q(strange-death) );
401a8022
YO
1873 print $status;
1874 ';
1875 fresh_perl_is($code, $expect, {}, "$bug - $test_name" );
1876 }
ba6840fb 1877 }
8df928d2
YO
1878 {
1879 fresh_perl_is('
1880 BEGIN{require q(test.pl);}
1881 watchdog(3);
1882 $SIG{ALRM} = sub {print "Timeout\n"; exit(1)};
1883 alarm 1;
1884 $_ = "a" x 1000 . "b" x 1000 . "c" x 1000;
1885 /.*a.*b.*c.*[de]/;
1886 ',"Timeout",{},"Test Perl 73464")
1887 }
33bc5d3d
KW
1888
1889 { # [perl #128686], crashed the the interpreter
1890 my $AE = chr utf8::unicode_to_native(0xC6);
1891 my $ae = chr utf8::unicode_to_native(0xE6);
1892 my $re = qr/[$ae\s]/i;
1893 ok($AE !~ $re, '/[\xE6\s]/i doesn\'t match \xC6 when not in UTF-8');
1894 utf8::upgrade $AE;
1895 ok($AE =~ $re, '/[\xE6\s]/i matches \xC6 when in UTF-8');
1896 }
1897
6d314683
YO
1898 {
1899 is(0+("\n" =~ m'\n'), 1, q|m'\n' should interpolate escapes|);
da42332b
YO
1900 }
1901
1902 {
2c2284d8
KW
1903 my $str = "a\xB6";
1904 ok( $str =~ m{^(a|a\x{b6})$}, "fix [perl #129950] - latin1 case" );
da42332b 1905 utf8::upgrade($str);
2c2284d8 1906 ok( $str =~ m{^(a|a\x{b6})$}, "fix [perl #129950] - utf8 case" );
da42332b 1907 }
5585e758
YO
1908 {
1909 my $got= run_perl( switches => [ '-l' ], prog => <<'EOF_CODE' );
1910 my $died= !eval {
1911 $_=qq(ab);
1912 print;
1913 my $p=qr/(?{ s!!x! })/;
1914 /$p/;
1915 print;
1916 /a/;
1917 /$p/;
1918 print;
1919 /b/;
1920 /$p/;
1921 print;
1922 //;
1923 1;
1924 };
1925 $error = $died ? ($@ || qq(Zombie)) : qq(none);
1926 print $died ? qq(died) : qq(lived);
1927 print qq(Error: $@);
1928EOF_CODE
1929 my @got= split /\n/, $got;
1930 is($got[0],"ab","empty pattern in regex codeblock: got expected start string");
1931 is($got[1],"xab",
1932 "empty pattern in regex codeblock: first subst with no last-match worked right");
1933 is($got[2],"xxb","empty pattern in regex codeblock: second subst worked right");
1934 is($got[3],"xxx","empty pattern in regex codeblock: third subst worked right");
1935 is($got[4],"died","empty pattern in regex codeblock: died as expected");
1936 like($got[5],qr/Error: Infinite recursion via empty pattern/,
1937 "empty pattern in regex codeblock: produced the right exception message" );
1938 }
7d79ca09
DM
1939
1940 # This test is based on the one directly above, which happened to
1941 # leak. Repeat the test, but stripped down to the bare essentials
1942 # of the leak, which is to die while executing a regex which is
1943 # already the current regex, thus causing the saved outer set of
1944 # capture offsets to leak. The test itself doesn't do anything
1945 # except sit around hoping not to be triggered by ASan
1946 {
1947 eval {
1948 my $s = "abcd";
1949 $s =~ m{([abcd]) (?{ die if $1 eq 'd'; })}gx;
1950 $s =~ //g;
1951 $s =~ //g;
1952 $s =~ //g;
1953 };
1954 pass("call to current regex doesn't leak");
1955 }
1956
1957
1958
8faf4f30
HS
1959 {
1960 # [perl #130495] /x comment skipping stopped a byte short, leading
1961 # to assertion failure or 'malformed utf-8 character" warning
1962 fresh_perl_is(
98c155b5 1963 "use utf8; m{a#\x{124}}x", '', {wide_chars => 1},
8faf4f30
HS
1964 '[perl #130495] utf-8 character at end of /x comment should not misparse',
1965 );
1966 }
871e132c
HS
1967 {
1968 # [perl #130522] causes out-of-bounds read detected by clang with
1969 # address=sanitized when length of the STCLASS string is greater than
1970 # length of target string.
1971 my $re = qr{(?=\0z)\0?z?$}i;
1972 my($yes, $no) = (1, "");
1973 for my $test (
1974 [ $no, undef, '<undef>' ],
1975 [ $no, '', '' ],
1976 [ $no, "\0", '\0' ],
1977 [ $yes, "\0z", '\0z' ],
1978 [ $no, "\0z\0", '\0z\0' ],
1979 [ $yes, "\0z\n", '\0z\n' ],
1980 ) {
1981 my($result, $target, $disp) = @$test;
1982 no warnings qw/uninitialized/;
1983 is($target =~ $re, $result, "[perl #130522] with target '$disp'");
1984 }
1985 }
2dfc11ec
HS
1986 {
1987 # [perl #129377] backref to an unmatched capture should not cause
1988 # reading before start of string.
1989 SKIP: {
1990 skip "no re-debug under miniperl" if is_miniperl;
1991 my $prog = <<'EOP';
1992use re qw(Debug EXECUTE);
1993"x" =~ m{ () y | () \1 }x;
1994EOP
1995 fresh_perl_like($prog, qr{
1996 \A (?! .* ^ \s+ - )
1997 }msx, { stderr => 1 }, "Offsets in debug output are not negative");
1998 }
1999 }
dc0dad9b
TC
2000 {
2001 # buffer overflow
495a482d
DM
2002
2003 # This test also used to leak - fixed by the commit which added
2004 # this line.
2005
dc0dad9b
TC
2006 fresh_perl_is("BEGIN{\$^H=0x200000}\ns/[(?{//xx",
2007 "Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE (?{/ at (eval 1) line 1.\n",
2008 {}, "buffer overflow for regexp component");
2009 }
d2ba660a
TC
2010 {
2011 # [perl #129281] buffer write overflow, detected by ASAN, valgrind
d2ba660a
TC
2012 fresh_perl_is('/0(?0)|^*0(?0)|^*(^*())0|/', '', {}, "don't bump whilem_c too much");
2013 }
6c4f4eb1
TC
2014 {
2015 # RT #131893 - fails with ASAN -fsanitize=undefined
2016 fresh_perl_is('qr/0(0?(0||00*))|/', '', {}, "integer overflow during compilation");
2017 }
bb152a4b
DM
2018
2019 {
2020 # RT #131575 intuit skipping back from the end to find the highest
2021 # possible start point, was potentially hopping back beyond pos()
2022 # and crashing by calling fbm_instr with a negative length
2023
2024 my $text = "=t=\x{5000}";
2025 pos($text) = 3;
2026 ok(scalar($text !~ m{(~*=[a-z]=)}g), "RT #131575");
2027 }
4dc12118
YO
2028 {
2029 fresh_perl_is('"AA" =~ m/AA{1,0}/','',{},"handle OPFAIL insert properly");
2030 }
12453e29
YO
2031 {
2032 fresh_perl_is('$_="0\x{1000000}";/^000?\0000/','',{},"dont throw assert errors trying to fbm past end of string");
2033 }
f8fb8615
KW
2034 { # [perl $132227]
2035 fresh_perl_is("('0ba' . ('ss' x 300)) =~ m/0B\\N{U+41}" . $sharp_s x 150 . '/i and print "1\n"', 1,{},"Use of sharp s under /di that changes to /ui");
f6cb9e97
KW
2036
2037 # A variation, but as far as khw knows not part of 132227
2038 fresh_perl_is("'0bssa' =~ m/0B" . $sharp_s . "\\N{U+41}" . '/i and print "1\n"', 1,{},"Use of sharp s under /di that changes to /ui");
f8fb8615 2039 }
5e20fb07
KW
2040 { # [perl $132164]
2041 fresh_perl_is('m m0*0+\Rm', "",{},"Undefined behavior in address sanitizer");
2042 }
d0d8d0cb 2043 { # [perl #133642]
2abbd513
KW
2044 fresh_perl_is('no warnings "experimental::vlb";
2045 m/((?<=(0?)))/', "",{},"Was getting 'Double free'");
d0d8d0cb 2046 }
d4c456e3
TC
2047 { # [perl #133782]
2048 # this would panic on DEBUGGING builds
2049 fresh_perl_is(<<'CODE', "ok\nok\n",{}, 'Bad length magic was left on $^R');
2050while( "\N{U+100}bc" =~ /(..?)(?{$^N})/g ) {
2051 print "ok\n" if length($^R)==length("$^R");
2052}
2053CODE
2054 }
e0814905 2055 { # [perl #133871], ASAN/valgrind out-of-bounds access
e0814905
KW
2056 fresh_perl_like('qr/(?|(())|())|//', qr/syntax error/, {}, "[perl #133871]");
2057 }
bfa9f5ee
KW
2058 { # [perl #133921], segfault
2059 fresh_perl_is('qr\ 40||ß+p00000F00000ù\Q00000ÿ00000x00000x0c0e0\Qx0\Qx0\x{0c!}\;\;î0\x\0ÿÿÿþ\0\0\0ù\Q`\Qx`\0\ 1{0c!}\ 1e;\0\0\0ù\ò`\Qm`\x{0c!}\;\;îçÿ \0\7fç\0\0\0!\0F\ 5\0\0/;îçÿù\Q\0\ 1\0\0x\10ÿÿÿÿ\0\0\0ù\0\0\0\7f`x{0c!}\ 1e;\0\0\0ù\Q`\Qx`\x{c!}\;\;îç!}\;îçÿù\Q\87 \x\0ÿÿÿÿ\0\0>=\Qx`\Qx`\0\0ù\ò`\Qx`\x{0c!};\;îçÿ \0F\ 5\0n0t0\0c \0\80\ 1d;t \0\0\0ù \0\7fç\80\0\0!00000000000000000000000m/00000000000000000000\ e00000000000m/\10\10\10\10\x{){} \10\10\10\10)|\10\10\ 4i', "", {}, "[perl #133921]");
2060 fresh_perl_is('\ 4|ß+W0ü0r0\Qx0\Qx0x0c0G00000000000000000O000000000x0x0x0c!}\;îçÿù\Q0 \x\0ÿÿÿÿ\0\0\0ù\Q`\Qx`\0\ 1{0d ;\0\0\0ù\ò`\Qm`\x{0c!}\;\;îçÿ \0\7fç\0\0\0!\0F\ 5\0\0/;îçÿù\Q\0\ 1\0\0x\10ÿÿÿÿ\0\0\0ù\0\0\0\7f`x{0c!}\ 1;\0\0\0ù\Q`\Qq`\x{c!}\;\;îç!}\;îçÿù\Q\87 \x\0ÿÿÿÿ\0\0>=\Qx`\Qx`\0\0ù\ò`\Qx`\x{0c!};\;îçÿ \00000000F\ 5\0m0t0\0c \0\80\ 1d;t \0\0\0ù \0\7fç\80\0\0!00000000000000000000000m/00000000000000000000\ e00000000000m/\10\10\10\10\x{){} \10\10\10\10)|\10\10\ 4\ 4i', "", {}, "[perl #133921]");
bf848a12
KW
2061
2062fresh_perl_is('s\ 4|ß+W0ü0f0\Qx0\Qx0x0c0G0xgive0000000000000O0h\8d000x0 \xòÿÿÿ\0\0ù\Q`\Q
2063
2064\1a
2065
2066
2067 ç
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080\ 5
2081
2082
2083x{0c!}\;\;çÿ \0\7fq0/i0/!\0F\ 5\0\0/;îçÿù\Q\0\ 1\0\0x\10ÿÿÿÿ\0\0\0ù\0\0\0\7f`x{0c!}\ 1e;\0\0\0ù\Q`\Qx`\x{0c!}\;ÿÿÿÿ!}\;îçÿù\Q\87\ 1\x\0ÿÿÿÿ\0\0>=\Qx`\Qx`\0\0ù\ò`ÿ\0\0>=\Qx`\Qx`\0\0ù\ò`\Qx`\x{0c!};\;îçÿ \0u00000F\ 5\0000t0\0p \0\80\ 1d? \0\0\0ù \0\7fç\80\0\0!00000000000000000000000m/00000000000000000000\ e00000000000m/0\0\10\10\10\\0\0\ 1\0} \10\10\10\10)|\10\10\ 4\ 4i', "", {}, "[perl #133921]");
2084
2085 fresh_perl_is('\ 4a aú\0\0úv sWtrt\10\0\ó||ß+W\ eü\16ef\0ù\Qx`\Qx`\x{1c!gGnuc given1111111111111O1111each\8d111\jx` \x\0òÿÿÿ\0\0\0ù\Qx`\Q
2086
2087
2088
2089
2090
2091 ç
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104\ 5
2105
2106
2107x{1c!}\;\;îçÿp \0\7fqr/elsif/!\0eF\ 5\0\0/;îçÿù\Q\0\ 1\0\0x\10ÿÿÿÿ\0\0\0ùHQx\0\0\0\7f`Lx{1c!}\ 1e;\0\0\0ù\Qx`\Qx`\x{1c!}\;ÿÿÿÿc!}\;îçÿù\Qx\87\ 1\x\0ÿÿÿÿ\0\0>=\Qx`\Qx`\0\0ù\òx`ÿ\0\0>=\Qx`\Qx`\0\0ù\òx`\Qx`\x{1c!}8;\;îçÿp \0unshifteF\ 5\0normat0\0cmp \0\80\ 1d?not \0\0\0ùp \0\7fç\80\0\0!0000000000000000000000000m/000000000000000000000\ e00000000000m/0R\0\10\10\10\\0\0\ 1\0} \10\10\10\10)|\10\10\ 4\10\10\10\10\10\ 1\aï||K??\8fp\80¿ÿÿfúd{\\ e{\ 4gri\ 4\ 4{\x{1x/}\0 ð¹NuntiÀh', "", {}, "[perl #133921]");
88b5a12c
KW
2108
2109 fresh_perl_is('s\ 4|ß+W0ü0f0\Qx0\Qx0x0c0g0c 000n0000000000000O0h\8d000x0 \xòÿÿÿ\0\0ù\Q`\Q
2110
2111
2112
2113
2114
2115 ç
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128\ 5
2129
2130
2131x{0c!}\;\;îçÿ \0\7f/0f/!\0F\ 5\0\0/;îçÿù\Q\0\ 1\0\0x\10ÿÿÿÿ\0\0\0ù\0\0\0\7f`x{0c!}\ 1;\0\0\0ù\Q`\Qx`\x{0c!}\;ÿÿÿÿ!}\;îçÿù\Q\87\ 1\x\0ÿÿÿÿ\0\0>=\Qx`\Qx`\0\0ù\ò`ÿ\0\0>=\Qx`\Qx`\0\0ù\ò`\Qx`\x{0c!};\;îçÿ \0000t0F\ 5\0000t0\0p \0\80\ 1d?n \0\0\0ù \0\7fç\80\0\0!00000000000000000000000m/00000000000000000000\ e00000000000m/\0\10\10\10\\0\0\ 1\0} \10\10\10\10)|\10\10\ 4\ 4i', "", {}, "[perl #133933]");
bfa9f5ee 2132 }
bb152a4b 2133
96d9b6ff
KW
2134 { # perl #133998]
2135 fresh_perl_is('print "\x{110000}" =~ qr/(?l)|[^\S\pC\s]/', 1, {},
2136 '/[\S\s]/l works');
2137 }
2138
0a5ed81e
KW
2139 { # perl #133995]
2140 use utf8;
3fb2d820
KW
2141 fresh_perl_is('"έδωσαν ελληνικήვე" =~ m/[^0](?=0)0?/', "",
2142 {wide_chars => 1},
2143 '[^0] doesnt crash on UTF-8 target string');
0a5ed81e
KW
2144 }
2145
f339d50e
KW
2146 { # [perl #133992] This is a tokenizer bug of parsing a pattern
2147 fresh_perl_is(q:$z = do {
2148 use utf8;
2149 "q!Ñ\82еÑ\81Ñ\82! =~ m'"
2150 };
2151 $z .= 'è(?#\84';
2152 $z .= "'";
2153 eval $z;:, "", {}, 'foo');
2154 }
2155
439a3bfe
KW
2156 { # [perl #134325]
2157 my $quote="\\Q";
2158 my $back="\\\\";
2159 my $ff="\xff";
2160 my $s = sprintf "/\\1|(|%s)%s%s /i",
2161 $quote x 8 . $back x 69,
2162 $quote x 5 . $back x 4,
2163 $ff x 48;
2164 like(runperl(prog => "$s", stderr => 1), qr/Unmatched \(/);
2165 }
2166
84281c31
A
2167} # End of sub run_tests
2168
21691;
10ef0e30
HS
2170
2171#
2172# ex: set ts=8 sts=4 sw=4 et:
2173#