threads / patch / 59221

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

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

## tl;dr

2 messages between Feb 9, 2023 and Feb 14, 2023. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Junio C Hamano· Feb 9, 2023, 23:05 UTC · lore
Daniel Abrecht <git-git@nodmarc.danielabrecht.ch> writes:
Show 21 quoted lines
> 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 <public@danielabrecht.ch>
> ---
>  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?
Show 5 quoted lines
> +	$base_url .= '/' if not $base_url =~ /\/$/;
> +
>  	# target of the home link on top of all pages
>  	our $home_link = $my_uri || "/";
>  }
Daniel Abrecht· Feb 14, 2023, 10:15 UTC · re: Junio C Hamano · lore
Am 2023-02-10 00:05, schrieb Junio C Hamano:
Show 14 quoted lines
> Daniel Abrecht <git-git@nodmarc.danielabrecht.ch> writes:
>> +	# 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?

After thinking about this for a while, I realized that this isn't as simple as I thought.

I'm currently using apache and some rewrite rules so I can access projects at /git/myproject.git/ (See my config below). So in my case, $base_url is /git at this point, and I need to add a /.

But if I didn't have those rewrite rules, I could instead access the repos using /git/gitweb.cgi/myproject.git/ . In that case, $base_url would be /git/gitweb.cgi at this point, so it does refer to the script / document. The assets are still at /git/ and not at /git/gitweb.cgi/, so links are relative to /git/gitweb.cgi/ but assets are relative to /git/. It seams relative URLs are only used for assets, so the $base_url should really be /git/gitweb.cgi or alternatively just /git/ there, and just adding a slash would be wrong in that case.

Given this, I no longer think I should change the way it currently is. I will just override $base_url in my config file instead.

<Macro gitweb $location>
   SetEnv GITWEB_CONFIG /etc/gitweb.conf
   SetEnv GIT_HTTP_EXPORT_ALL
   ScriptAliasMatch \
   "(?x)^/.*/(.*\.git/(HEAD | \
       info/refs | \
       objects/(info/[^/]+ | \
          [0-9a-f]{2}/[0-9a-f]{38} | \
          pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
       git-(upload|receive)-pack))$" \
   /usr/lib/git-core/git-http-backend/$1
   Alias $location/ /usr/share/gitweb/
   RewriteRule 
^$location/.*\.git/(HEAD|info|objects|refs|git-(upload|receive)-pack) - 
[E=GIT_PROJECT_ROOT:%{DOCUMENT_ROOT}$location/,PT,END]
   RewriteRule ^$location/(.*\.git(/.*)?)?$ $location/gitweb.cgi/$1 
[E=GIT_PROJECT_ROOT:%{DOCUMENT_ROOT}$location/,L,PT]
   <Location $location>
     Require all granted
     AllowOverride None
   </Location>
   <Directory /usr/share/gitweb/>
     Options +FollowSymLinks +ExecCGI
     AddHandler cgi-script .cgi
   </Directory>
</Macro>
<VirtualHost *:443>
   Use VHostSSL projects.dpa.li
   DocumentRoot /var/www/projects.dpa.li/
   Use gitweb /git
</VirtualHost>

← back to recent threads