This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
heredoc after "" in s/// in eval
authorFather Chrysostomos <sprout@cpan.org>
Mon, 20 Aug 2012 19:57:29 +0000 (12:57 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 21 Aug 2012 21:11:01 +0000 (14:11 -0700)
commit565b52dfca4375468541e36d53e8a2aba372c056
tree4f816fcf51789e90a5c5c29abeb2ddd93b009d93
parent458391bde9932f85da1dbbd0c2a3fdc3229bb00d
heredoc after "" in s/// in eval

This works fine:

eval ' s//<<END.""/e; print
Just another Perl hacker,
END
'or die $@
__END__
Just another Perl hacker,

But this doesn’t:

eval ' s//"$1".<<END/e; print
Just another Perl hacker,
END
'or die $@
__END__
Can't find string terminator "END" anywhere before EOF at (eval 1) line 1.

It fails because PL_sublex_info.super_buf*, added by commit
0244c3a403, are not localised, so, after the "", s/// sees its own
buffer pointers in those variables, instead of its parent string eval.

This used to happen only with s///e inside s///e, but that was because
here-docs would peek inside the parent linestr buffer only inside
s///e, and not other quote-like operators.  That was fixed in
recent commits.

Simply moving the assignment of super_buf* into sublex_push does solve
the bug for a simple "", as "" does sublex_start, but not sublex_push.
We do need to localise those variables for "${\''}", however.
t/base/lex.t
toke.c