Skip to content

Commit

Permalink
[perl #128307] Fix ‘foo ? require : bar’
Browse files Browse the repository at this point in the history
The lexer’s bareword-parser that kicks in after it sees ‘require’ was
getting confused by the single colon, since it assumed that if the
thing that followed began with a letter or colon it must be a package
or module name.  Hence, require with : after it was parsed as
require "", but with a ‘bareword’ "".  The lexer should be checking
for two colons, not just one.
  • Loading branch information
Father Chrysostomos committed Jun 3, 2016
1 parent 198aaf3 commit e7127e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion t/op/lex.t
Expand Up @@ -7,7 +7,7 @@ use warnings;

BEGIN { chdir 't' if -d 't'; require './test.pl'; }

plan(tests => 25);
plan(tests => 26);

{
no warnings 'deprecated';
Expand Down Expand Up @@ -209,3 +209,10 @@ fresh_perl_is(
{ stderr => 1 },
's;@{<<a; [perl #123995]'
);

fresh_perl_is(
'$_ = q-strict.pm-; 1 ? require : die;'
.' print qq-ok\n- if $INC{q-strict.pm-}',
"ok\n",
'foo ? require : bar [perl #128307]'
);
2 changes: 1 addition & 1 deletion toke.c
Expand Up @@ -2012,7 +2012,7 @@ S_force_word(pTHX_ char *start, int token, int check_keyword, int allow_pack)
start = skipspace(start);
s = start;
if (isIDFIRST_lazy_if(s,UTF)
|| (allow_pack && *s == ':') )
|| (allow_pack && *s == ':' && s[1] == ':') )
{
s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
if (check_keyword) {
Expand Down

0 comments on commit e7127e2

Please sign in to comment.