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

* Re: [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
  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
  0 siblings, 2 replies; 13+ messages in thread
From: Jakub Narebski @ 2009-02-12 22:03 UTC (permalink / raw)
  To: Giuseppe Bilotta; +Cc: git, Junio C Hamano, Giuseppe Bilotta, Petr Baudis

On Thu, 12 Feb 2009, Giuseppe Bilotta wrote:

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

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

        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
> 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:
Acked-by: Jakub Narebski <jnareb@gmail.com>

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

-- 
Jakub Narebski
Poland

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

* Re: [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
  2009-02-12 22:03 ` Jakub Narebski
@ 2009-02-13  7:36   ` Giuseppe Bilotta
  2009-02-13  7:40   ` Giuseppe Bilotta
  1 sibling, 0 replies; 13+ messages in thread
From: Giuseppe Bilotta @ 2009-02-13  7:36 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git, Junio C Hamano, Petr Baudis

On Thu, Feb 12, 2009 at 11:03 PM, Jakub Narebski <jnareb@gmail.com> wrote:
> On Thu, 12 Feb 2009, Giuseppe Bilotta wrote:
>
>> From: Giuseppe Bilotta <oblomov@rbot.ratry.ru>
>
> Why different email? Was it intended, or was it an accident, and
> authorship of this patch should be to
>
>        Giuseppe Bilotta <giuseppe.bilotta@gmail.com>

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

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

> Signoff?

Will add that too.

-- 
Giuseppe "Oblomov" Bilotta

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

* [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
  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
  1 sibling, 1 reply; 13+ messages in thread
From: Giuseppe Bilotta @ 2009-02-13  7:40 UTC (permalink / raw)
  To: git; +Cc: Jakub Narebski, Junio C Hamano, Petr Baudis, 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.

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.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 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.5

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

* Re: [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
  2009-02-13  7:40   ` Giuseppe Bilotta
@ 2009-02-13  8:45     ` Jakub Narebski
  2009-02-14  2:14       ` Junio C Hamano
  0 siblings, 1 reply; 13+ messages in thread
From: Jakub Narebski @ 2009-02-13  8:45 UTC (permalink / raw)
  To: Giuseppe Bilotta; +Cc: git, Junio C Hamano, Petr Baudis

On Fri, 13 Feb 2009, Giuseppe Bilotta wrote:

> 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.
> 
> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>

Sounds good. I don't use gitweb as DirectoryIndex myself, but
Acked-by: Jakub Narebski <jnareb@gmail.com>

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

-- 
Jakub Narebski
Poland

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

* Re: [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
  2009-02-13  8:45     ` Jakub Narebski
@ 2009-02-14  2:14       ` Junio C Hamano
  2009-02-14  2:42         ` Jakub Narebski
  0 siblings, 1 reply; 13+ messages in thread
From: Junio C Hamano @ 2009-02-14  2:14 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Giuseppe Bilotta, git, Petr Baudis

Jakub Narebski <jnareb@gmail.com> writes:

>> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
>
> Sounds good. I don't use gitweb as DirectoryIndex myself, but
> Acked-by: Jakub Narebski <jnareb@gmail.com>
>
>> +# 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.

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

* Re: [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
  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 10:04           ` [PATCH v3] " Jakub Narebski
  0 siblings, 2 replies; 13+ messages in thread
From: Jakub Narebski @ 2009-02-14  2:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Giuseppe Bilotta, git, Petr Baudis

On Sat, 14 Feb 2009, Junio C Hamano wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
> 
>>> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
>>
>> Sounds good. I don't use gitweb as DirectoryIndex myself, but
>> Acked-by: Jakub Narebski <jnareb@gmail.com>
>>
>>> +# 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.

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

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 t/t9500-gitweb-standalone-no-errors.sh |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index 43cd6ee..7c6f70b 100755
--- i/t/t9500-gitweb-standalone-no-errors.sh
+++ w/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
 

-- 
Jakub Narebski
Poland

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

* Re: [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
  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
  1 sibling, 1 reply; 13+ messages in thread
From: Giuseppe Bilotta @ 2009-02-14  8:52 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Junio C Hamano, git, Petr Baudis

On Sat, Feb 14, 2009 at 3:42 AM, Jakub Narebski <jnareb@gmail.com> wrote:
> On Sat, 14 Feb 2009, Junio C Hamano wrote:
>> Jakub Narebski <jnareb@gmail.com> writes:
>>
>>>> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
>>>
>>> Sounds good. I don't use gitweb as DirectoryIndex myself, but
>>> Acked-by: Jakub Narebski <jnareb@gmail.com>
>>>
>>>> +# 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.

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

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

-- 
Giuseppe "Oblomov" Bilotta

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

* Re: [PATCH] gitweb: fix wrong base URL when non-root DirectoryIndex
  2009-02-14  8:52           ` Giuseppe Bilotta
@ 2009-02-14  9:30             ` Junio C Hamano
  0 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2009-02-14  9:30 UTC (permalink / raw)
  To: Giuseppe Bilotta; +Cc: Jakub Narebski, git, Petr Baudis

Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:

> 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]

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

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

* [PATCH v3] gitweb: fix wrong base URL when non-root DirectoryIndex
  2009-02-14  2:42         ` Jakub Narebski
  2009-02-14  8:52           ` Giuseppe Bilotta
@ 2009-02-14 10:04           ` Jakub Narebski
  2009-02-14 14:29             ` Giuseppe Bilotta
  1 sibling, 1 reply; 13+ messages in thread
From: Jakub Narebski @ 2009-02-14 10:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Giuseppe Bilotta, git, Petr Baudis

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

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

* Re: [PATCH v3] gitweb: fix wrong base URL when non-root  DirectoryIndex
  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
  0 siblings, 2 replies; 13+ messages in thread
From: Giuseppe Bilotta @ 2009-02-14 14:29 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Junio C Hamano, git, Petr Baudis

On Sat, Feb 14, 2009 at 11:04 AM, Jakub Narebski <jnareb@gmail.com> wrote:
>
> 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.

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

-- 
Giuseppe "Oblomov" Bilotta

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

* [PATCHv4] gitweb: fix wrong base URL when non-root DirectoryIndex
  2009-02-14 14:29             ` Giuseppe Bilotta
@ 2009-02-15  9:18               ` Giuseppe Bilotta
  2009-02-15 19:33               ` [PATCH v3] " Junio C Hamano
  1 sibling, 0 replies; 13+ messages in thread
From: Giuseppe Bilotta @ 2009-02-15  9:18 UTC (permalink / raw)
  To: git; +Cc: Jakub Narebski, Junio C Hamano, Petr Baudis, 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.

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

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

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 8dffa3f..7c48181 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.5.6.5

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

* Re: [PATCH v3] gitweb: fix wrong base URL when non-root  DirectoryIndex
  2009-02-14 14:29             ` Giuseppe Bilotta
  2009-02-15  9:18               ` [PATCHv4] " Giuseppe Bilotta
@ 2009-02-15 19:33               ` Junio C Hamano
  1 sibling, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2009-02-15 19:33 UTC (permalink / raw)
  To: Giuseppe Bilotta; +Cc: Jakub Narebski, git, Petr Baudis

Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:

> On Sat, Feb 14, 2009 at 11:04 AM, Jakub Narebski <jnareb@gmail.com> wrote:
>>
>> 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.
>
>> -               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.

^ permalink raw reply	[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.