I've got a php script that needs to pass a username and password via exec to a perl script. The problem is valid password characters were getting escaped...
Here's a little perl function I wrote to fix it.
sub unescape_string {
my $string = shift;
# all these interpolated regex's are slow, so if there's no
# backslash in the string don't bother with it
# index() is faster then a regex
if ( ! index($string,'\\\\') ) {
return $string;
}
my @characters = ('#', '&', ';', '`', '|', '*', '?', '~', '<', '>', '^', '(', ')',
'[', ']', '{', '}', '$', '\\', ',', ' ', '\x0A', '\xFF' );
my $character;
foreach $character (@characters) {
$character = quotemeta($character);
my $pattern = "\\\\(" . $character . ")";
$string =~ s/$pattern/$1/g;
}
return $string;
}
Hope this is useful.