All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
@ 2009-02-12 21:11 Giuseppe Bilotta
  2009-02-12 22:03 ` Jakub Narebski
  0 siblings, 1 reply; 13+ messages in thread
From: Giuseppe Bilotta @ 2009-02-12 21:11 UTC (permalink / raw)
  To: git; +Cc: Jakub Narebski, Junio C Hamano, Giuseppe Bilotta

From: Giuseppe Bilotta <oblomov@rbot.ratry.ru>

CGI::url() has some issues when rebuilding the script URL if the script
is a DirectoryIndex.

One of these issue is the inability to strip PATH_INFO, which is why we
had to do it ourselves.

Another issue is that the resulting URL cannot be used for the <base>
tag: it works if we're the DirectoryIndex at the root level, but not
otherwise.

We fix this by building the proper base URL ourselves, and improve the
documentation about the need to strip PATH_INFO manually while we're at
it.
---
 gitweb/gitweb.perl |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c2c8080..48cfd5f 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -27,15 +27,23 @@ our $version = "++GIT_VERSION++";
 our $my_url = $cgi->url();
 our $my_uri = $cgi->url(-absolute => 1);
 
-# if we're called with PATH_INFO, we have to strip that
-# from the URL to find our real URL
-# we make $path_info global because it's also used later on
+# When the script is used as DirectoryIndex, the URL does not contain the name
+# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
+# have to do it ourselves. We make $path_info global because it's also used
+# later on
 our $path_info = $ENV{"PATH_INFO"};
 if ($path_info) {
 	$my_url =~ s,\Q$path_info\E$,,;
 	$my_uri =~ s,\Q$path_info\E$,,;
 }
 
+# Another issue with the script being the DirectoryIndex is that the resulting
+# $my_url data is not the full script URL: this is good, because we want
+# generated links to keep implying the script name if it wasn't explicitly
+# indicated in the URL we're handling, but it means that $my_url cannot be used
+# as base URL. Therefore, we have to build the base URL ourselves:
+our $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
+
 # core git executable to use
 # this can just be "git" if your webserver has a sensible PATH
 our $GIT = "++GIT_BINDIR++/git";
@@ -2908,7 +2916,7 @@ EOF
 	# the stylesheet, favicon etc urls won't work correctly with path_info
 	# unless we set the appropriate base URL
 	if ($ENV{'PATH_INFO'}) {
-		print "<base href=\"".esc_url($my_url)."\" />\n";
+		print "<base href=\"".esc_url($base_url)."\" />\n";
 	}
 	# print out each stylesheet that exist, providing backwards capability
 	# for those people who defined $stylesheet in a config file
-- 
1.5.6.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-02-15 19:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-12 21:11 [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex Giuseppe Bilotta
2009-02-12 22:03 ` Jakub Narebski
2009-02-13  7:36   ` Giuseppe Bilotta
2009-02-13  7:40   ` Giuseppe Bilotta
2009-02-13  8:45     ` Jakub Narebski
2009-02-14  2:14       ` Junio C Hamano
2009-02-14  2:42         ` Jakub Narebski
2009-02-14  8:52           ` Giuseppe Bilotta
2009-02-14  9:30             ` Junio C Hamano
2009-02-14 10:04           ` [PATCH v3] " Jakub Narebski
2009-02-14 14:29             ` Giuseppe Bilotta
2009-02-15  9:18               ` [PATCHv4] " Giuseppe Bilotta
2009-02-15 19:33               ` [PATCH v3] " Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.