Skip to content

Commit

Permalink
Handle /[#]/ and /[(?#]/ with code blocks
Browse files Browse the repository at this point in the history
This is a regression in 5.18.0.

In something like /[#](?{})/x, the perl toker incorrectly sees the '#' as a
comment and skips the code block without parsing it.
  • Loading branch information
iabyn committed Jul 31, 2013
1 parent 985afbc commit c30fc27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions t/re/re_tests
Expand Up @@ -1764,3 +1764,15 @@ A+?(*PRUNE)BC(?{}) AAABC y $& ABC
A+(*THEN)BC(?{}) AAABC y $& AAABC
A+(*PRUNE)BC(?{}) AAABC y $& AAABC
# vim: softtabstop=0 noexpandtab
/[#]/ a#b y $& #
/[#]b/ a#b y $& #b
/[#]/x a#b y $& #
/[#]b/x a#b y $& #b
/[#](?{})/x a#b y $& #
/[#](??{'b'})/x a#b y $& #b
/(?#)(?{})b/ a#b y $& b
/(?#)(??{'b'})/ a#b y $& b
/[(?#](?{})b/ a#b y $& #b
/[(?#](??{'b'})/ a#b y $& #b
/(?#)(?{})b/x a#b y $& b
/(?#)(??{'b'})/x a#b y $& b
6 changes: 3 additions & 3 deletions toke.c
Expand Up @@ -3285,12 +3285,12 @@ S_scan_const(pTHX_ char *start)
* char, which will be done separately.
* Stop on (?{..}) and friends */

else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
else if (*s == '(' && PL_lex_inpat && s[1] == '?' && !in_charclass) {
if (s[2] == '#') {
while (s+1 < send && *s != ')')
*d++ = NATIVE_TO_NEED(has_utf8,*s++);
}
else if (!PL_lex_casemods && !in_charclass &&
else if (!PL_lex_casemods &&
( s[2] == '{' /* This should match regcomp.c */
|| (s[2] == '?' && s[3] == '{')))
{
Expand All @@ -3299,7 +3299,7 @@ S_scan_const(pTHX_ char *start)
}

/* likewise skip #-initiated comments in //x patterns */
else if (*s == '#' && PL_lex_inpat &&
else if (*s == '#' && PL_lex_inpat && !in_charclass &&
((PMOP*)PL_lex_inpat)->op_pmflags & RXf_PMf_EXTENDED) {
while (s+1 < send && *s != '\n')
*d++ = NATIVE_TO_NEED(has_utf8,*s++);
Expand Down

0 comments on commit c30fc27

Please sign in to comment.