Skip to content

Commit cacfc09

Browse files
jaysoffiangitster
authored andcommitted
gitweb: URL-decode $my_url/$my_uri when stripping PATH_INFO
When gitweb is used as a DirectoryIndex, it attempts to strip PATH_INFO on its own, as $cgi->url() fails to do so. However, it fails to account for the fact that PATH_INFO has already been URL-decoded by the web server, but the value returned by $cgi->url() has not been. This causes the stripping to fail whenever the URL contains encoded characters. To see this in action, setup gitweb as a DirectoryIndex and then use it on a repository with a directory containing a space in the name. Navigate to tree view, examine the gitweb generated html and you'll see a link such as: <a href="/test.git/tree/HEAD:/directory with spaces">directory with spaces</a> When clicked on, the browser will URL-encode this link, giving a $cgi->url() of the form: /test.git/tree/HEAD:/directory%20with%20spaces While PATH_INFO is: /test.git/tree/HEAD:/directory with spaces Fix this by calling unescape() on both $my_url and $my_uri before stripping PATH_INFO from them. Signed-off-by: Jay Soffian <[email protected]> Acked-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 785ee49 commit cacfc09

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

gitweb/gitweb.perl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ sub evaluate_uri {
5454
# to build the base URL ourselves:
5555
our $path_info = decode_utf8($ENV{"PATH_INFO"});
5656
if ($path_info) {
57+
# $path_info has already been URL-decoded by the web server, but
58+
# $my_url and $my_uri have not. URL-decode them so we can properly
59+
# strip $path_info.
60+
$my_url = unescape($my_url);
61+
$my_uri = unescape($my_uri);
5762
if ($my_url =~ s,\Q$path_info\E$,, &&
5863
$my_uri =~ s,\Q$path_info\E$,, &&
5964
defined $ENV{'SCRIPT_NAME'}) {

0 commit comments

Comments
 (0)