diff options
author | Tony Cook <tony@develop-help.com> | 2017-07-04 11:44:06 +1000 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2017-08-14 16:02:42 +1000 |
commit | 3cb4cde3dd4d2af2f5065053905708bffa5168f9 (patch) | |
tree | d42884431205d22c8d053d329f4fa7af5143ed1b | |
parent | 9ef07b785bb0b703029b3e0ef819565c76e1f8d5 (diff) | |
download | perl-3cb4cde3dd4d2af2f5065053905708bffa5168f9.tar.gz |
(perl #124368) make /foo/o; /$null/ act consistently
Previously the /o would be inherited by the second match if the first
match was successful, but only on non-threaded builds.
The op-tree rewriting done on non-threaded builds could also confuse
the interpreter, possibly resulting in the match op receiving
the argument intended for the regcomp op.
-rw-r--r-- | pp_ctl.c | 10 | ||||
-rw-r--r-- | t/re/pat.t | 17 |
2 files changed, 18 insertions, 9 deletions
@@ -163,15 +163,9 @@ PP(pp_regcomp) /* handle the empty pattern */ if (!RX_PRELEN(PM_GETRE(pm)) && PL_curpm) { if (PL_curpm == PL_reg_curpm) { - if (PL_curpm_under) { - if (PL_curpm_under == PL_reg_curpm) { - Perl_croak(aTHX_ "Infinite recursion via empty pattern"); - } else { - pm = PL_curpm_under; - } + if (PL_curpm_under && PL_curpm_under == PL_reg_curpm) { + Perl_croak(aTHX_ "Infinite recursion via empty pattern"); } - } else { - pm = PL_curpm; } } diff --git a/t/re/pat.t b/t/re/pat.t index fb6d4c4a69..cf97ecdf07 100644 --- a/t/re/pat.t +++ b/t/re/pat.t @@ -23,7 +23,7 @@ BEGIN { skip_all('no re module') unless defined &DynaLoader::boot_DynaLoader; skip_all_without_unicode_tables(); -plan tests => 837; # Update this when adding/deleting tests. +plan tests => 843; # Update this when adding/deleting tests. run_tests() unless caller; @@ -138,6 +138,21 @@ sub run_tests { $null = ""; $xyz =~ /$null/; is($&, $xyz, $message); + + # each entry: regexp, match string, $&, //o match success + my @tests = + ( + [ "", "xy", "x", 1 ], + [ "y", "yz", "y", !1 ], + ); + for my $test (@tests) { + my ($re, $str, $matched, $omatch) = @$test; + $xyz =~ /x/o; + ok($str =~ /$re/, "$str matches /$re/"); + is($&, $matched, "on $matched"); + $xyz =~ /x/o; + is($str =~ /$re/o, $omatch, "$str matches /$re/o (or not)"); + } } { |