From: Jakub Narebski <jnareb@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>,
git@vger.kernel.org, Petr Baudis <pasky@suse.cz>
Subject: [PATCH v3] gitweb: fix wrong base URL when non-root DirectoryIndex
Date: Sat, 14 Feb 2009 11:04:34 +0100 [thread overview]
Message-ID: <200902141104.35042.jnareb@gmail.com> (raw)
In-Reply-To: <200902140342.26270.jnareb@gmail.com>
From: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
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
comment about the need to strip PATH_INFO manually while we're at it.
Additionally t/t9500-gitweb-standalone-no-errors.sh had to be modified
to set SCRIPT_NAME variable (CGI standard states that it MUST be set,
and now gitweb uses it if PATH_INFO is not empty, as is the case for
some of tests in t9500).
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
On Sat, 14 Feb 2009, Jakub Narebski wrote:
> So patch should be squashed with the following improvement to test
> suite:
[...]
Here it is. (And with [PATCH v3] :-)).
Additionally I tried to make it more robust, first by constructing
$base_url _only_ when needed (when we strip PATH_INFO), and second
by checking if SCRIPT_NAME is defined.
Passes test (after its modification), but not testes itself!
P.S. I wonder why Giuseppe's patch failed to apply, and failed
to do fallback 3-way merge...
Applying: gitweb: fix wrong base URL when non-root DirectoryIndex
error: patch failed: gitweb/gitweb.perl:2908
error: gitweb/gitweb.perl: patch does not apply
fatal: sha1 information is lacking or useless (gitweb/gitweb.perl).
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0001.
On top of v1.6.2-rc0-64-ge9cc02f, gitweb/gitweb.perl is 54108742...
gitweb/gitweb.perl | 28 ++++++++++++++++++++++------
t/t9500-gitweb-standalone-no-errors.sh | 6 ++++--
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 5410874..83c2ad7 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -27,13 +27,29 @@ 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
+# Base URL for relative URLs in gitweb ($logo, $favicon, ...),
+# needed and used only for URLs with nonempty PATH_INFO
+our $base_url = $my_url;
+
+# 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.
+#
+# 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, if we needed to strip PATH_INFO, then we know that we have
+# to build the base URL ourselves:
our $path_info = $ENV{"PATH_INFO"};
if ($path_info) {
- $my_url =~ s,\Q$path_info\E$,,;
- $my_uri =~ s,\Q$path_info\E$,,;
+ if (($my_url =~ s,\Q$path_info\E$,, ||
+ $my_uri =~ s,\Q$path_info\E$,,) &&
+ defined $ENV{'SCRIPT_NAME'}) {
+ $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
+ }
}
# core git executable to use
@@ -2908,7 +2924,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
diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index 43cd6ee..7c6f70b 100755
--- a/t/t9500-gitweb-standalone-no-errors.sh
+++ b/t/t9500-gitweb-standalone-no-errors.sh
@@ -43,9 +43,11 @@ gitweb_run () {
GATEWAY_INTERFACE="CGI/1.1"
HTTP_ACCEPT="*/*"
REQUEST_METHOD="GET"
+ SCRIPT_NAME="$TEST_DIRECTORY/../gitweb/gitweb.perl"
QUERY_STRING=""$1""
PATH_INFO=""$2""
- export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD QUERY_STRING PATH_INFO
+ export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
+ SCRIPT_NAME QUERY_STRING PATH_INFO
GITWEB_CONFIG=$(pwd)/gitweb_config.perl
export GITWEB_CONFIG
@@ -54,7 +56,7 @@ gitweb_run () {
# written to web server logs, so we are not interested in that:
# we are interested only in properly formatted errors/warnings
rm -f gitweb.log &&
- perl -- "$TEST_DIRECTORY/../gitweb/gitweb.perl" \
+ perl -- "$SCRIPT_NAME" \
>/dev/null 2>gitweb.log &&
if grep "^[[]" gitweb.log >/dev/null 2>&1; then false; else true; fi
--
1.6.1
next prev parent reply other threads:[~2009-02-14 10:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Jakub Narebski [this message]
2009-02-14 14:29 ` [PATCH v3] " Giuseppe Bilotta
2009-02-15 9:18 ` [PATCHv4] " Giuseppe Bilotta
2009-02-15 19:33 ` [PATCH v3] " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200902141104.35042.jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=giuseppe.bilotta@gmail.com \
--cc=pasky@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).