Escape ' character when executing script

This commit is contained in:
x3 2024-03-14 17:45:15 +01:00
parent 891b01315f
commit cbb7f861e1
Signed by: x3
GPG Key ID: 7E9961E8AD0E240E
1 changed files with 8 additions and 1 deletions

View File

@ -159,6 +159,12 @@ sub parse_config {
close($fh); close($fh);
} }
sub sh_escape {
my ($txt) = @_;
$txt =~ s/'/'\\''/;
return $txt;
}
sub exec_script { sub exec_script {
my ($feed, $xmlitem) = @_; my ($feed, $xmlitem) = @_;
@ -171,7 +177,8 @@ sub exec_script {
my $key = $1; my $key = $1;
#print("Matched: $key\n"); #print("Matched: $key\n");
next if not exists $xmlitem->{$key}; next if not exists $xmlitem->{$key};
$cmd =~ s/\$$key/$xmlitem->{$key}/; my $escaped_val = sh_escape($xmlitem->{$key});
$cmd =~ s/\$$key/$escaped_val/;
} }
qx($cmd); qx($cmd);