Subject: Re: [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end

From: Junio C Hamano <[email-masked]>
Date: Thu, 09 Feb 2023 15:05:20 -0800

Daniel Abrecht <[email-masked]> writes:

> In HTML, if there is a base tag like `<base href="/a/b">`, a relative
> URL like
> `c/d` will be resolved by the browser as `a/c/d` and not as
> `a/b/c/d`. But with
> a base tag like `<base href="/a/b/">` it will result in `a/b/c/d`.
>
> Signed-off-by: Daniel Abrecht <[email-masked]>
> ---
>  gitweb/gitweb.perl | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index e66eb3d9ba..edcee1652c 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -74,6 +74,11 @@ sub evaluate_uri {
>  		}
>  	}
>
> +	# $base_url is later used in the <base> tag as a URL, if it
> doesn't end in a /

It seems an overlog line was wrapped around and broke the patch.

> +	# the browser will strip away the last component for relative URLs.
> +	# Add the / if it's missing.

The above is not an incorrect statement per-se, but if $base were
pointing at the document, we would likely break if we add an extra
slash.  Don't we want to say something like 

	# $base_url at this point points at a directory, not a
        # single document, and later is used in the <base> tag.
        # Make sure it ends in a '/'.  Otherwise, we'd lose the last
        # component when forming a relative URL.

perhaps?

> +	$base_url .= '/' if not $base_url =~ /\/$/;
> +
>  	# target of the home link on top of all pages
>  	our $home_link = $my_uri || "/";
>  }