This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse funny keys/values in hh properly
authorFather Chrysostomos <sprout@cpan.org>
Wed, 7 Dec 2011 07:07:49 +0000 (23:07 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 7 Dec 2011 14:15:36 +0000 (06:15 -0800)
commit035146a3ca31411488f684bee10fdd30d32ba7c3
treefb939a38e77d412b7b5a6728b3434f6ce29f16d8
parent51530e339190db7a300f01c70489f30e1f4a5d01
Deparse funny keys/values in hh properly

Simply putting '...' or q(...) around a string is not sufficient to
quote it properly, allowing this sort of ‘fun’:

$ perl -l -MO=Deparse -e'BEGIN{$^H{"'\''.'\''"} = "um);\n    exit("}print'
BEGIN { $/ = "\n"; $\ = "\n"; }
sub BEGIN {
    $^H{q['.']} = "um);\n    exit(";
}
BEGIN {
    $^H{''.''} = q(um);
    exit();
}
print $_;
-e syntax OK

And B::Deparse already has a facility for quoting strings, so why
not use it?
dist/B-Deparse/Deparse.pm
dist/B-Deparse/t/deparse.t