This also fixes percent and caret escaping and documents some batch file parameter escaping quirks.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/WineRunTask.pl | 9 +-------- testbot/lib/WineTestBot/Utils.pm | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/testbot/bin/WineRunTask.pl b/testbot/bin/WineRunTask.pl index 53e9e5001..432bf51d8 100755 --- a/testbot/bin/WineRunTask.pl +++ b/testbot/bin/WineRunTask.pl @@ -479,14 +479,7 @@ elsif ($Step->Type eq "suite") $Info .= $VM->Details; } # Escape the arguments for cmd's command interpreter - my $EMail = $AdminEMail; - $EMail =~ s/"/\"/g; - $EMail =~ s/%/%%/g; - $EMail =~ s/%/%%/g; - $Info =~ s/"/\"/g; - $Info =~ s/%/%%/g; - $Info =~ s/%/%%/g; - $Script .= "-q -o $RptFileName -t $Tag -m "$EMail" -i "$Info"\r\n"; + $Script .= "-q -o $RptFileName -t $Tag -m ". BatchQuote($AdminEMail) ." -i ". BatchQuote($Info) ."\r\n"; $Script .= "$FileName -q -s $RptFileName\r\n" if (!$Mission->{nosubmit}); } Debug(Elapsed($Start), " Sending the script: [$Script]\n"); diff --git a/testbot/lib/WineTestBot/Utils.pm b/testbot/lib/WineTestBot/Utils.pm index 83f60fa07..97fb1292a 100644 --- a/testbot/lib/WineTestBot/Utils.pm +++ b/testbot/lib/WineTestBot/Utils.pm @@ -333,6 +333,31 @@ sub IsValidFileName($) =pod =over 12
+=item C<BatchQuote()> + +Quotes strings so they can be used in Windows batch files. + +Note that escaping is subtly different between the command line, batch files +and inside for loops in batch files! This function ignores the latter case. + +=back +=cut +sub BatchQuote($) +{ + my ($Str)=@_; + + $Str =~ s/"/\"/g; + # Backslashes don't need to be doubled, they only take on a special meaning + # when followed by a double quote. Single quotes and backquotes don't have + # a special meaning either. + $Str =~ s/%/%%/g; + $Str =~ s/^/^^/g; + return ""$Str""; +} + +=pod +=over 12 + =item C<ShQuote()>
Quotes strings so they can be used in shell commands.