From: Junio C Hamano Date: Thu, 10 Nov 2005 17:52:36 GMT Subject: Re: git and cogito update, gitweb problem Message-ID: <7vvez0z8yj.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <20051110120201.GE22064@schottelius.org> Nico -telmich- Schottelius writes: > I just wanted to present you an automatic git and cogito updating script, > but I've still the problem with '+' in filenames in gitweb [0]. Project names (and perhaps tag names) could contain characters that need to be URL escaped as well. I think this minimally should fix it for the list of files on the commit page (a=commit) but I see the same problem in other pages everywhere. --- diff --git a/gitweb.cgi b/gitweb.cgi index b8f1537..7b05fe2 100755 --- a/gitweb.cgi +++ b/gitweb.cgi @@ -10,7 +10,7 @@ use strict; use warnings; use CGI qw(:standard :escapeHTML -nosticky); -use CGI::Util qw(unescape); +use CGI::Util qw(unescape escape); use CGI::Carp qw(fatalsToBrowser); use Fcntl ':mode'; @@ -1393,7 +1395,7 @@ sub git_tree { my $t_type = $2; my $t_hash = $3; my $t_name = $4; - $file_key = ";f=$base$t_name"; + $file_key = ";f=" . escape("$base$t_name"); if ($alternate) { print "\n"; } else { @@ -1628,23 +1630,26 @@ sub git_commit { $expires = "+1d"; } git_header_html(undef, $expires); + + my $eproject = escape($project); + print "
\n" . - $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") . - " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") . - " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") . + $cgi->a({-href => "$my_uri?p=$eproject;a=summary"}, "summary") . + " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=shortlog;h=$hash"}, "shortlog") . + " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=log;h=$hash"}, "log") . " | commit"; if (defined $co{'parent'}) { - print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff"); + print " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=commitdiff;h=$hash"}, "commitdiff"); } - print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" . + print " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" . "

\n"; if (defined $co{'parent'}) { print "
\n" . - $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" . + $cgi->a({-href => "$my_uri?p=$eproject;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" . "
\n"; } else { print "
\n" . - $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" . + $cgi->a({-href => "$my_uri?p=$eproject;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" . "
\n"; } print "
\n" . @@ -1665,19 +1670,19 @@ sub git_commit { print "" . "tree" . "" . - $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", class => "list"}, $co{'tree'}) . + $cgi->a({-href => "$my_uri?p=$eproject;a=tree;h=$co{'tree'};hb=$hash", class => "list"}, $co{'tree'}) . "" . - "" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . + "" . $cgi->a({-href => "$my_uri?p=$eproject;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "" . "\n"; my $parents = $co{'parents'}; foreach my $par (@$parents) { print "" . "parent" . - "" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par", class => "list"}, $par) . "" . + "" . $cgi->a({-href => "$my_uri?p=$eproject;a=commit;h=$par", class => "list"}, $par) . "" . "" . - $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, "commit") . - " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par"}, "commitdiff") . + $cgi->a({-href => "$my_uri?p=$eproject;a=commit;h=$par"}, "commit") . + " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=commitdiff;h=$hash;hp=$par"}, "commitdiff") . "" . "\n"; } @@ -1726,6 +1731,7 @@ sub git_commit { my $status = $5; my $similarity = $6; my $file = $7; + my $efile = escape($file); if ($alternate) { print "\n"; } else { @@ -1738,16 +1744,16 @@ sub git_commit { $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777); } print "" . - $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "\n" . + $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$to_id;hb=$hash;f=$efile", -class => "list"}, escapeHTML($file)) . "\n" . "[new " . file_type($to_mode) . "$mode_chng]\n" . - "" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . "\n"; + "" . $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$to_id;hb=$hash;f=$efile"}, "blob") . "\n"; } elsif ($status eq "D") { print "" . - $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "\n" . + $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$from_id;hb=$hash;f=$efile", -class => "list"}, escapeHTML($file)) . "\n" . "[deleted " . file_type($from_mode). "]\n" . "" . - $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, "blob") . - " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . + $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$from_id;hb=$hash;f=$efile"}, "blob") . + " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=history;h=$hash;f=$efile"}, "history") . "\n" } elsif ($status eq "M" || $status eq "T") { my $mode_chnge = ""; @@ -1767,18 +1773,18 @@ sub git_commit { } print ""; if ($to_id ne $from_id) { - print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)); + print $cgi->a({-href => "$my_uri?p=$eproject;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$efile", -class => "list"}, escapeHTML($file)); } else { - print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)); + print $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$to_id;hb=$hash;f=$efile", -class => "list"}, escapeHTML($file)); } print "\n" . "$mode_chnge\n" . ""; - print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob"); + print $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$to_id;hb=$hash;f=$efile"}, "blob"); if ($to_id ne $from_id) { - print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff"); + print " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$efile"}, "diff"); } - print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n"; + print " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=history;h=$hash;f=$efile"}, "history") . "\n"; print "\n"; } elsif ($status eq "R") { my ($from_file, $to_file) = split "\t", $file; @@ -1787,14 +1793,14 @@ sub git_commit { $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777); } print "" . - $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file", -class => "list"}, escapeHTML($to_file)) . "\n" . + $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$to_id;hb=$hash;f=$to_file", -class => "list"}, escapeHTML($to_file)) . "\n" . "[moved from " . - $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file", -class => "list"}, escapeHTML($from_file)) . + $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$from_id;hb=$hash;f=$from_file", -class => "list"}, escapeHTML($from_file)) . " with " . (int $similarity) . "% similarity$mode_chng]\n" . "" . - $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"}, "blob"); + $cgi->a({-href => "$my_uri?p=$eproject;a=blob;h=$to_id;hb=$hash;f=$to_file"}, "blob"); if ($to_id ne $from_id) { - print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file"}, "diff"); + print " | " . $cgi->a({-href => "$my_uri?p=$eproject;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file"}, "diff"); } print "\n"; }