Skip to contentSkip to conversation

gitweb: fix wrong base URL when non-root DirectoryIndex

PATCH In review Giuseppe Bilotta 3 participants 13 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitweb: fix wrong base URL when non-root DirectoryIndex

From: Giuseppe Bilotta <[email protected]>

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(-)
gitweb/gitweb.perl +12 -4
index c2c8080..48cfd5f 100755
@@ -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
Signature · 1 line
1.5.6.4
Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Giuseppe Bilotta

From: Giuseppe Bilotta <[email protected]>

Why different email? Was it intended, or was it an accident, and authorship of this patch should be to

Giuseppe Bilotta <[email protected]>

Quoted 7 lines

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.

Quoted 7 lines

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.

Very good. The only thing I wonder about is if we should add this info also to gitweb/README, or if it is good as it is now.

Signoff?

I do not use gitweb as DirectoryIndex, but it looks sane, so:

Quoted 48 lines
---
 gitweb/gitweb.perl |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +12 -4
index c2c8080..48cfd5f 100755
@@ -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
Signature · 1 line
1.5.6.4
Signature · 2 lines
Jakub Narebski
Poland
#2 lore raw

PATCH 1/1 gitweb: fix wrong base URL when non-root DirectoryIndex

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(-)
gitweb/gitweb.perl +12 -4
index c2c8080..48cfd5f 100755
@@ -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
Signature · 1 line
1.5.6.5
Acked-by on v1 1/1
#3 lore raw
Quoted 10 lines · Giuseppe Bilotta

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.

Quoted 5 lines

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.

Sounds good. I don't use gitweb as DirectoryIndex myself, but

Quoted 48 lines
---
 gitweb/gitweb.perl |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +12 -4
index c2c8080..48cfd5f 100755
@@ -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
Signature · 1 line
1.5.6.5
Signature · 2 lines
Jakub Narebski
Poland
#4 lore raw
Quoted 11 lines · Jakub Narebski
Quoted 1 line

Sounds good. I don't use gitweb as DirectoryIndex myself, but

gitweb/gitweb.perl our $version = "++GIT_VERSION++"; · line 45

Quoted 6 lines
gitweb/gitweb.perl +6 -0
+# 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'};

Breaks t9500 with

    [Sat Feb 14 02:12:59 2009] gitweb.perl: Use of uninitialized value in concatenation (.) or string at /pub/git/t/../gitweb/gitweb.perl line 45.

Please be more careful when giving an Ack, and more importantly please do not send a patch that does not even pass the test suite by itself.

#5 lore raw
Quoted 16 lines · Junio C Hamano
Quoted 11 lines · Jakub Narebski
Quoted 1 line

Sounds good. I don't use gitweb as DirectoryIndex myself, but

Review

Quoted 6 lines
(quoted diff) +6 -0
+# 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'};

Breaks t9500 with

Quoted 5 lines
    [Sat Feb 14 02:12:59 2009] gitweb.perl: Use of uninitialized value in
    concatenation (.) or string at /pub/git/t/../gitweb/gitweb.perl line 45. 

Please be more careful when giving an Ack, and more importantly please do not send a patch that does not even pass the test suite by itself.

Actually this is not a bug in _gitweb_, but in _test_ itself.

In t/t9500-gitweb-standalone-no-errors.sh we run gitweb.perl as a standalone script (not from a web server), and we set _some_ of CGI environmental variables. Up till now we could get by using only most important ones: GATEWAY_INTERFACE (I'm not sure if needed), HTTP_ACCEPT (used to select Content-Type to use), REQUEST_METHOD (git_feed exits early on HEAD request), and of course QUERY_STRING and PATH_INFO. The required variable SCRIPT_NAME is simply not set...

BTW. we could have set also SERVER_NAME, but it is not required by gitweb (gitweb can deal with situation when it is unset)...

So patch should be squashed with the following improvement to test suite:

-- >8 --

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 requires it if PATH_INFO is not empty, as is the case for some of tests in t9500).

---
 t/t9500-gitweb-standalone-no-errors.sh |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
t/t9500-gitweb-standalone-no-errors.sh +4 -2
index 43cd6ee..7c6f70b 100755
@@ -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
 
Signature · 2 lines
Jakub Narebski
Poland
#6 lore raw

PATCH v3 1/1 gitweb: fix wrong base URL when non-root DirectoryIndex

From: Giuseppe Bilotta <[email protected]>

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).

---

Quoted 2 lines · Jakub Narebski

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(-)
gitweb/gitweb.perl +22 -6
index 5410874..83c2ad7 100755
@@ -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
t/t9500-gitweb-standalone-no-errors.sh +4 -2
index 43cd6ee..7c6f70b 100755
@@ -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
 
Signature · 1 line
1.6.1
#7 lore raw
Quoted 3 lines · Jakub Narebski

P.S. I wonder why Giuseppe's patch failed to apply, and failed to do fallback 3-way merge...

Because it depends on an additional quoting fix that I sent to the mailing list but that apparently didn't get through.

gitweb/gitweb.perl EOF · line 2927

Quoted 2 lines
gitweb/gitweb.perl +1 -1
-               print '<base href="'.esc_url($my_url).'" />\n';
+               print '<base href="'.esc_url($base_url).'" />\n';

The quoting fix was here: double quotes are needed because otherwise the \n gets in literally. We can probably squash it with this patch. Gimme a sec and I'll cook it up again.

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#8 lore raw

PATCH v4 1/1 gitweb: fix wrong base URL when non-root DirectoryIndex

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).

---

There was a bug in Jakub's rewritten logic for the PATH_INFO stripping:
using || instead of && meant that $my_uri was not being stripped if $my_url was, resulting in wrong relative links all around. Instead, if we can strip PATH_INFO from $my_url then we can (and must) strip it from $my_uri too (&&), and then check for the definition of SCRIPT_NAME.

This patch also included a quoting patch that apparently didn't make it to the list: the <base> tag was inserting a literal \n instead of a newline. Since that line got rewritten anyway, I thought it wasn't a big deal to squash it in.

 gitweb/gitweb.perl                     |   28 ++++++++++++++++++++++------
 t/t9500-gitweb-standalone-no-errors.sh |    6 ++++--
 2 files changed, 26 insertions(+), 8 deletions(-)
gitweb/gitweb.perl +22 -6
index 8dffa3f..7c48181 100755
@@ -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
t/t9500-gitweb-standalone-no-errors.sh +4 -2
index 43cd6ee..7c6f70b 100755
@@ -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
 
Signature · 1 line
1.5.6.5
#9 lore raw
In reply to Giuseppe Bilotta
Quoted 8 lines · Giuseppe Bilotta
Quoted 3 lines · Jakub Narebski

P.S. I wonder why Giuseppe's patch failed to apply, and failed to do fallback 3-way merge...

Because it depends on an additional quoting fix that I sent to the mailing list but that apparently didn't get through.

Quoted 6 lines

gitweb/gitweb.perl EOF · line 2927

Quoted 2 lines
gitweb/gitweb.perl +1 -1
-               print '<base href="'.esc_url($my_url).'" />\n';
+               print '<base href="'.esc_url($base_url).'" />\n';

The quoting fix was here: double quotes are needed because otherwise the \n gets in literally. We can probably squash it with this patch. Gimme a sec and I'll cook it up again.

Thanks, both.

#10 lore raw
In reply to Jakub Narebski
Quoted 17 lines · Jakub Narebski
Quoted 16 lines · Junio C Hamano
Quoted 11 lines · Jakub Narebski
Quoted 1 line

Sounds good. I don't use gitweb as DirectoryIndex myself, but

Review

Quoted 6 lines
(quoted diff) +6 -0
+# 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'};

Breaks t9500 with

Quoted 5 lines
Quoted 5 lines
    [Sat Feb 14 02:12:59 2009] gitweb.perl: Use of uninitialized value in
    concatenation (.) or string at /pub/git/t/../gitweb/gitweb.perl line 45.

Please be more careful when giving an Ack, and more importantly please do not send a patch that does not even pass the test suite by itself.

Sorry, my fault. For future reference for myself, is there a way to only run the gitweb tests of the testsuite?

Quoted 9 lines

Actually this is not a bug in _gitweb_, but in _test_ itself.

In t/t9500-gitweb-standalone-no-errors.sh we run gitweb.perl as a standalone script (not from a web server), and we set _some_ of CGI environmental variables. Up till now we could get by using only most important ones: GATEWAY_INTERFACE (I'm not sure if needed), HTTP_ACCEPT (used to select Content-Type to use), REQUEST_METHOD (git_feed exits early on HEAD request), and of course QUERY_STRING and PATH_INFO. The required variable SCRIPT_NAME is simply not set...

Thank you for the additional patch. One thing we should also probably add to the test is the HTTP_IF_MODIFIED_SINCE. I will try to think of a bunch of tests to run against feed production after I implement the reflog data check.

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#11 lore raw
Quoted 2 lines · Giuseppe Bilotta

For future reference for myself, is there a way to only run the gitweb tests of the testsuite?

cd t && sh ./t9500-gitweb-standalone-no-errors.sh [-i] [-v]

Quoted 4 lines

Thank you for the additional patch. One thing we should also probably add to the test is the HTTP_IF_MODIFIED_SINCE. I will try to think of a bunch of tests to run against feed production after I implement the reflog data check.

Thanks.

#12 lore raw
In reply to Jakub Narebski
Quoted 8 lines · Jakub Narebski
Quoted 1 line · Giuseppe Bilotta

From: Giuseppe Bilotta <[email protected]>

Why different email? Was it intended, or was it an accident, and authorship of this patch should be to

Giuseppe Bilotta <[email protected]>

I created this patch on a different computer and forgot to set the authorship as usual. I'll resend.

Quoted 2 lines

Very good. The only thing I wonder about is if we should add this info also to gitweb/README, or if it is good as it is now.

I think there is no need to adjust the README, as in fact this fix is needed to make sure that the instructions in README are correct even for subpaths.

Quoted 1 line

Signoff?

Will add that too.

Signature · 1 line
Giuseppe "Oblomov" Bilotta