Francois Gouget : testbot: Add BatchQuote() to quote and escape batch parameters.

Alexandre Julliard julliard at winehq.org
Thu Sep 12 16:27:54 CDT 2019


Module: tools
Branch: master
Commit: cdef2d8f07f0befc17ec88d1bfe63d537d07ef10
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=cdef2d8f07f0befc17ec88d1bfe63d537d07ef10

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Thu Sep 12 14:36:55 2019 +0200

testbot: Add BatchQuote() to quote and escape batch parameters.

This also fixes percent and caret escaping and documents some batch file
parameter escaping quirks.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 53e9e50..432bf51 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 83f60fa..97fb129 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.




More information about the wine-cvs mailing list