This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix two minor s//.../e parsing bugs
authorFather Chrysostomos <sprout@cpan.org>
Thu, 30 Aug 2012 22:57:18 +0000 (15:57 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 31 Aug 2012 01:18:12 +0000 (18:18 -0700)
commit9c74ccc90967bf358f43629a26ebd70e7f15f83a
tree2b9856a58fdc684f7de317480c88ab9846b3bea7
parent5c49e90fd624f3ab1cdb1f1d8e4f0525d7881b99
Fix two minor s//.../e parsing bugs

It may be an odd place to allow comments, but s//"" # hello/e has\
always worked, *unless* there happens to be a null before the first #.

scan_subst in toke.c wraps the replacement text in do { ... } when the
/e flag is present.

It was adding a line break before the final } if the replacement text
contained #, because otherwise the } would be commented out.

But to find the # it was using strchr, which stops at the first null.
So eval "s//'\0'#/e" would fail.

It makes little sense to me to check whether the replacement contains
# before adding the line break.  It would be faster just to add the
line break without checking.

But then I discovered this bug:

s//"#" . <<END/e;
foo
END
__END__
Can't find string terminator "END" anywhere before EOF at - line 1.

So now I have two bugs to fix.

The easiest solution seems to be to omit the line break and make the
comment parser skip the } at the end of a s///e replacement.
t/base/lex.t
toke.c