diff options
author | David Mitchell <davem@iabyn.com> | 2013-07-31 22:41:17 +0100 |
---|---|---|
committer | Ricardo Signes <rjbs@cpan.org> | 2013-07-31 22:34:49 -0400 |
commit | f84462707ac6f483f96c5128ce25fc5b9fa2cc85 (patch) | |
tree | 7fde5a0c7fca38492467d5550ddf3570c667123d | |
parent | 7aca8ac205466d581286769767f9840714d1c5e1 (diff) | |
download | perl-f84462707ac6f483f96c5128ce25fc5b9fa2cc85.tar.gz |
Handle /[#]/ and /[(?#]/ with code blocks
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.
(cherry picked from commit c30fc27b4df65a43710b25dd1d2a57d78ee2fe33)
-rw-r--r-- | t/re/re_tests | 12 | ||||
-rw-r--r-- | toke.c | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/t/re/re_tests b/t/re/re_tests index 7e7fc855f7..4d89e69e70 100644 --- a/t/re/re_tests +++ b/t/re/re_tests @@ -1737,3 +1737,15 @@ ab[c\\\](??{"x"})]{3}d ab\\](d y - - m?^xy\?$? xy? y $& xy? # 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 @@ -3163,12 +3163,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] == '{'))) { @@ -3177,7 +3177,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++); |