Francois Gouget : testbot/cgi: Add Page::jsQuote() to escape JavaScript strings.

Alexandre Julliard julliard at winehq.org
Tue Mar 29 15:04:24 CDT 2022


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

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Tue Mar 29 18:00:20 2022 +0200

testbot/cgi: Add Page::jsQuote() to escape JavaScript strings.

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

---

 testbot/lib/ObjectModel/CGI/Page.pm     | 20 ++++++++++++++++++++
 testbot/lib/WineTestBot/CGI/PageBase.pm |  5 +----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/testbot/lib/ObjectModel/CGI/Page.pm b/testbot/lib/ObjectModel/CGI/Page.pm
index c5f8a33..a791559 100644
--- a/testbot/lib/ObjectModel/CGI/Page.pm
+++ b/testbot/lib/ObjectModel/CGI/Page.pm
@@ -144,6 +144,26 @@ sub escapeHTML($$)
 =pod
 =over 12
 
+=head1 C<jsQuote()>
+
+Quotes a string for JavaScript code.
+
+=back
+=cut
+
+sub jsQuote($$)
+{
+  my ($self, $String) = @_;
+
+  $String =~ s~\\~\\\\~g;
+  $String =~ s~"~\\\"~g;
+  $String =~ s~\n~\\n~g;
+  return "\"$String\"";
+}
+
+=pod
+=over 12
+
 =head1 C<SetRefreshInterval()>
 
 Sets the page refresh interval in seconds.
diff --git a/testbot/lib/WineTestBot/CGI/PageBase.pm b/testbot/lib/WineTestBot/CGI/PageBase.pm
index e87e1d6..19a5aec 100644
--- a/testbot/lib/WineTestBot/CGI/PageBase.pm
+++ b/testbot/lib/WineTestBot/CGI/PageBase.pm
@@ -323,10 +323,7 @@ sub GenerateErrorPopup($$)
   {
     print "<script type='text/javascript'>\n";
     print "<!--\n";
-    $ErrMessage =~ s~\\~\\\\~g;
-    $ErrMessage =~ s~"~\\\"~g;
-    $ErrMessage =~ s~\n~\\n~g;
-    print "function ShowError() { alert(\"$ErrMessage\"); }\n";
+    print "function ShowError() { alert(", $Page->jsQuote($ErrMessage), "); }\n";
     my $ErrField = $Page->GetErrField();
     if ($ErrField)
     {




More information about the wine-cvs mailing list