Subject: | Error in unescape function |
The current _unescape function doesn't work correctly.
For example, test with "\\r" as input. This should return "\r" as
output because this is just an escaped backslash followed by an "r".
However in current code, \r is evaluated first and therefore this
unescaping will fail ...
A fixed version below.
Cheers,
-- Geert
my %unesc =
(
"\\" => "\\",
"\"" => "\"",
"a" => "\a",
"b" => "\b",
"t" => "\t",
"n" => "\n",
"f" => "\f",
"r" => "\r",
"e" => "\e",
"v" => "\013",
);
sub _unescape
{
# Looks like we have to do this one ourselves
my ($string) = @_;
# Unescape any \X for various characters X (including \\ and \")
# NOTE : Shouldn't "v" be added to the list below ?
$string =~ s/\\([\\\"abtnfre])/$unesc{$1}/esg;
# Unescape \OCTAL for various octal values
$string =~ s/\\(0[0-7]+)/chr(oct($1))/esg;
return $string;
}