Skip to content

Commit

Permalink
RT #119125: continue /[#$x]/x not interpolating
Browse files Browse the repository at this point in the history
the earlier fix for /[#](?{})/x, although correct, as a
side-effect fixed another long-standing bug where /[#$x]/x
didn't interpolate the var $x. Although fixing that is good,
it's too big a change for maint, so keep the old buggy behaviour
for now.
  • Loading branch information
iabyn authored and rjbs committed Aug 4, 2013
1 parent 704c2f1 commit 0268238
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
19 changes: 18 additions & 1 deletion t/re/pat.t
Expand Up @@ -20,7 +20,7 @@ BEGIN {
require './test.pl';
}

plan tests => 470; # Update this when adding/deleting tests.
plan tests => 472; # Update this when adding/deleting tests.

run_tests() unless caller;

Expand Down Expand Up @@ -1363,6 +1363,23 @@ EOP
like($c, $re, "mixed up-/downgraded pattern matches upgraded string");
}

{
# RT #119125
# the earlier fix for /[#](?{})/x, although correct, as a
# side-effect fixed another long-standing bug where /[#$x]/x
# didn't interpolate the var $x. Although fixing that is good,
# it's too big a change for maint, so keep the old buggy behaviour
# for now.

my $b = 'cd';
my $s = 'abcd$%#&';
$s =~ s/[a#$b%]/X/g;
is ($s, 'XbXX$XX&', 'RT #119125 without /x');
$s = 'abcd$%#&';
$s =~ s/[a#$b%]/X/gx;
is ($s, 'XXcdXXX&', 'RT #119125 with /x');
}

} # End of sub run_tests

1;
17 changes: 15 additions & 2 deletions toke.c
Expand Up @@ -3177,10 +3177,23 @@ S_scan_const(pTHX_ char *start)
}

/* likewise skip #-initiated comments in //x patterns */
else if (*s == '#' && PL_lex_inpat && !in_charclass &&
else if (*s == '#' && PL_lex_inpat &&
((PMOP*)PL_lex_inpat)->op_pmflags & RXf_PMf_EXTENDED) {
while (s+1 < send && *s != '\n')
while (s+1 < send && *s != '\n') {
/* for maint-5.18, half-fix #-in-charclass bug:
* *do* recognise codeblocks: /[#](?{})/
* *don't* recognise interpolated vars: /[#$x]/
*/
if (in_charclass && !PL_lex_casemods && s+3 < send &&
s[0] == '(' &&
s[1] == '?' &&
( s[2] == '{'
|| (s[2] == '?' && s[3] == '{')))
break;
*d++ = NATIVE_TO_NEED(has_utf8,*s++);
}
if (s+ 1 < send && *s != '\n')
break; /* we stopped on (?{}), not EOL */
}

/* no further processing of single-quoted regex */
Expand Down

0 comments on commit 0268238

Please sign in to comment.