Use standard function for escaping HTML plus some more minor refactoring of the code.
authorjelmer <jelmer@1e5ffdc8-eadd-0310-9daa-9cb4117fe24b>
Sun, 11 Feb 2007 00:36:18 +0000 (00:36 +0000)
committerjelmer <jelmer@1e5ffdc8-eadd-0310-9daa-9cb4117fe24b>
Sun, 11 Feb 2007 00:36:18 +0000 (00:36 +0000)
git-svn-id: file:///home/svn/build-farm/trunk@502 1e5ffdc8-eadd-0310-9daa-9cb4117fe24b

tests/util.pl
web/build.pl
web/history.pm
web/util.pm

index 2395b6f55d2ee475b74fd35d6ddb97cefc0ca790..f2e7e75156e9241f91ab9846fd92012dcbb537b3 100755 (executable)
@@ -5,7 +5,8 @@ use FindBin qw($RealBin);
 use lib "$RealBin/..";
 use lib "$RealBin/../web";
 
-use Test::More tests => 27;
+use Test::More tests => 21;
+use CGI qw/:standard/;
 use strict;
 
 use util;
@@ -14,13 +15,6 @@ is(2, util::count_lines("foo\nbar"));
 is(1, util::count_lines("bar"));
 is(1, util::count_lines(""));
 
-is("&amp;", util::cgi_escape("&"));
-is("1 &amp;&amp; 2", util::cgi_escape("1 && 2"));
-is("&lt;&gt;", util::cgi_escape("<>"));
-is("&amp;amp;", util::cgi_escape("&amp;"));
-is("&quot;", util::cgi_escape("\""));
-is("nothing", util::cgi_escape("nothing"));
-
 is("foo.bar", util::ChangeExtension("foo.old", "bar"));
 is("foo.png", util::ChangeExtension("foo.png", "png"));
 is("foobar.png", util::ChangeExtension("foobar", "png"));
index a65998c8995d187f9d41376c7a9b613d5b155fbf..e1cdf4af8106a31066fe07e776110c63e07aedb7 100755 (executable)
@@ -32,7 +32,7 @@ use util;
 use history;
 use POSIX;
 use Data::Dumper;
-use CGI;
+use CGI qw/:standard/;
 use File::stat;
 
 my $WEBDIR = "$RealBin";
@@ -660,7 +660,7 @@ sub view_build() {
     $err = util::FileLoad("$file.err");
     
     if ($log) {
-               $log = util::cgi_escape($log);
+               $log = escapeHTML($log);
 
                if ($log =~ /(.*)/) { $uname=$1; }
                if ($log =~ /CFLAGS=(.*)/) { $cflags=$1; }
@@ -668,7 +668,7 @@ sub view_build() {
     }
 
     if ($err) {
-               $err = util::cgi_escape($err);
+               $err = escapeHTML($err);
     }
 
     print "<h2>Host information:</h2>\n";
index c558ebaa61c81fe8f3919c82d8a24079496b13cd..49b25674855a8966859934b5beef53d09b09d0d0 100644 (file)
@@ -13,7 +13,7 @@ use strict qw{vars};
 use util;
 use POSIX;
 use Data::Dumper;
-use CGI;
+use CGI qw/:standard/;
 use File::stat;
 
 my $req = new CGI;
@@ -52,16 +52,7 @@ my $unpacked_dir = "/home/ftp/pub/unpacked";
 
 ###############################################
 # work out a URL so I can refer to myself in links
-my $myself = $req->self_url;
-if ($myself =~ /(.*)[?].*/) {
-    $myself = $1;
-}
-if ($myself =~ /http:\/\/.*\/(.*)/) {
-    $myself = $1;
-}
-
-# for now, hard code the self url - need to sanitize self_url
-$myself = "http://build.samba.org/";
+my $myself = $req->url();
 
 ################################################
 # print an error on fatal errors
@@ -128,8 +119,7 @@ sub diff_pretty($)
 # change the given source paths into links
 sub web_paths($$)
 {
-    my $tree = shift;
-    my $paths = shift;
+    my ($tree, $paths) = @_;
     my $ret = "";
 
     if (grep {/$tree/} keys %cvs_trees) {
@@ -137,15 +127,13 @@ sub web_paths($$)
        $ret .= sprintf($cvs_trees{$tree}, $1, $1);
        $paths = $2;
       }
-    }
-    elsif (grep {/$tree/} keys %svn_trees) {
+    } elsif (grep {/$tree/} keys %svn_trees) {
            while ($paths =~ /\s*([^\s]+)(.*)/) {
            
                    $ret .= sprintf($svn_trees{$tree}, $1, $1);
                    $paths = $2;
            }
-    }
-    elsif (grep {/$tree/} keys %bzr_trees) {
+    } elsif (grep {/$tree/} keys %bzr_trees) {
            while ($paths =~ /\s*([^\s]+)(.*)/) {
                    $ret .= sprintf($bzr_trees{$tree}, $1, $1);
                    $paths = $2;
@@ -159,9 +147,8 @@ sub web_paths($$)
 # show one row of history table
 sub history_row($$)
 {
-    my $entry = shift;
-    my $tree = shift;
-    my $msg = util::cgi_escape($entry->{MESSAGE});
+    my ($entry, $tree) = @_;
+    my $msg = escapeHTML($entry->{MESSAGE});
     my $t = POSIX::asctime(POSIX::gmtime($entry->{DATE}));
     my $age = util::dhm_time(time()-$entry->{DATE});
 
@@ -219,9 +206,8 @@ sub history_row($$)
 # show one row of history table
 sub history_row_text($$)
 {
-    my $entry = shift;
-    my $tree = shift;
-    my $msg = util::cgi_escape($entry->{MESSAGE});
+    my ($entry, $tree) = @_;
+    my $msg = escapeHTML($entry->{MESSAGE});
     my $t = POSIX::asctime(POSIX::gmtime($entry->{DATE}));
     my $age = util::dhm_time(time()-$entry->{DATE});
 
@@ -271,7 +257,7 @@ sub svn_diff($$$)
     chomp $current_revision;
     $current_revision =~ s/.*?(\d+)$/$1/;
 
-       fatal("unknown revision") if ($revision !~ /^\d+$/ or $revision < 0 or
+    fatal("unknown revision") if ($revision !~ /^\d+$/ or $revision < 0 or
                                          $revision > $current_revision);
 
     my $log = util::LoadStructure("$HISTORYDIR/history.$tree");
@@ -315,7 +301,7 @@ sub svn_diff($$$)
 
     if ($text_html eq "html") {
        print "<!-- $cmd --!>\n";
-       $diff = util::cgi_escape($diff);
+       $diff = escapeHTML($diff);
        $diff = diff_pretty($diff);
        print "<pre>$diff</pre>\n";
     }
@@ -328,10 +314,7 @@ sub svn_diff($$$)
 # show recent cvs entries
 sub cvs_diff($$$$)
 {
-    my $author = shift;
-    my $date = shift;
-    my $tree = shift;
-    my $text_html = shift;
+    my ($author, $date, $tree, $text_html) = @_;
     my $module;
 
     my $log = util::LoadStructure("$HISTORYDIR/history.$tree");
@@ -399,7 +382,7 @@ in cvs</b>
                        
                        if ($text_html eq "html") { 
                            print "<!-- $cmd --!>\n";
-                           $diff = util::cgi_escape($diff);
+                           $diff = escapeHTML($diff);
                            $diff = diff_pretty($diff);
                            print "<pre>$diff</pre>\n";
                        } else {
@@ -418,7 +401,7 @@ in cvs</b>
 
                    if ($text_html eq "html") { 
                        print "<!-- $cmd --!>\n";
-                       $diff = util::cgi_escape($diff);
+                       $diff = escapeHTML($diff);
                        $diff = diff_pretty($diff);
                        print "<pre>$diff</pre>\n";
                    }
@@ -486,11 +469,10 @@ sub bzr_diff($$$)
 
     if ($text_html eq "html") {
        print "<!-- $cmd --!>\n";
-       $diff = util::cgi_escape($diff);
+       $diff = escapeHTML($diff);
        $diff = diff_pretty($diff);
        print "<pre>$diff</pre>\n";
-    }
-    else {
+    } else {
        print "$diff\n";
     }
 }
@@ -499,7 +481,6 @@ sub bzr_diff($$$)
 # get commit history for the given tree
 sub history($)
 {
-
     my $tree = shift;
     my (%authors) = ('ALL' => 1);
     my $author;
index 2d89a9d700e79f4398172e2093bc09e67bad26ed..2b31b15a400e5c7213728fcb160929fdcf73c9bb 100644 (file)
@@ -185,20 +185,6 @@ sub cgi_gzip()
     }
 }
 
-##########################################
-# escape a string for cgi
-sub cgi_escape($)
-{
-    my $s = shift;
-
-    $s =~ s/&/&amp;/mg;
-    $s =~ s/</&lt;/mg;
-    $s =~ s/>/&gt;/mg;
-    $s =~ s/"/&quot;/mg;
-
-    return $s;
-}
-
 ##########################################
 # count the number of lines in a buffer
 sub count_lines($)