* [PATCH] gitweb: fix base url set if PATH_INFO is used, add a / at the end.
@ 2023-02-03 21:42 Daniel Abrecht
2023-02-06 22:02 ` Junio C Hamano
2023-02-09 22:26 ` [PATCH v2] " Daniel Abrecht
0 siblings, 2 replies; 5+ messages in thread
From: Daniel Abrecht @ 2023-02-03 21:42 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
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`. So by
adding a slash there, the browser should now search the
files at the correct location.
Signed-off-by: Daniel Abrecht <public@danielabrecht.ch>
---
gitweb/gitweb.perl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e66eb3d9ba..acb2cce5f6 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4217,7 +4217,7 @@ sub git_header_html {
# 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($base_url)."\" />\n";
+ print "<base href=\"".esc_url($base_url)."/\" />\n";
}
print_header_links($status);
--
2.39.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] gitweb: fix base url set if PATH_INFO is used, add a / at the end.
2023-02-03 21:42 [PATCH] gitweb: fix base url set if PATH_INFO is used, add a / at the end Daniel Abrecht
@ 2023-02-06 22:02 ` Junio C Hamano
2023-02-09 22:26 ` [PATCH v2] " Daniel Abrecht
1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2023-02-06 22:02 UTC (permalink / raw)
To: Daniel Abrecht; +Cc: git
Daniel Abrecht <git-git@nodmarc.danielabrecht.ch> 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`. So by
> adding a slash there, the browser should now search the
> files at the correct location.
>
> Signed-off-by: Daniel Abrecht <public@danielabrecht.ch>
> ---
> gitweb/gitweb.perl | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index e66eb3d9ba..acb2cce5f6 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -4217,7 +4217,7 @@ sub git_header_html {
> # 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($base_url)."\" />\n";
> + print "<base href=\"".esc_url($base_url)."/\" />\n";
Doesn't this need to be somewhat conditional? Sites like repo.or.cz
currently give <base href="/" /> presumably because $base_url for
them is '/', and this change will make them show double slashes
instead of a single one, no?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end
2023-02-03 21:42 [PATCH] gitweb: fix base url set if PATH_INFO is used, add a / at the end Daniel Abrecht
2023-02-06 22:02 ` Junio C Hamano
@ 2023-02-09 22:26 ` Daniel Abrecht
2023-02-09 23:05 ` Junio C Hamano
1 sibling, 1 reply; 5+ messages in thread
From: Daniel Abrecht @ 2023-02-09 22:26 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
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 /
+ # the browser will strip away the last component for relative URLs.
+ # Add the / if it's missing.
+ $base_url .= '/' if not $base_url =~ /\/$/;
+
# target of the home link on top of all pages
our $home_link = $my_uri || "/";
}
--
2.39.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end
2023-02-09 22:26 ` [PATCH v2] " Daniel Abrecht
@ 2023-02-09 23:05 ` Junio C Hamano
2023-02-14 10:15 ` Daniel Abrecht
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2023-02-09 23:05 UTC (permalink / raw)
To: Daniel Abrecht; +Cc: git
Daniel Abrecht <git-git@nodmarc.danielabrecht.ch> 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 <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?
> + $base_url .= '/' if not $base_url =~ /\/$/;
> +
> # target of the home link on top of all pages
> our $home_link = $my_uri || "/";
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end
2023-02-09 23:05 ` Junio C Hamano
@ 2023-02-14 10:15 ` Daniel Abrecht
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Abrecht @ 2023-02-14 10:15 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Am 2023-02-10 00:05, schrieb Junio C Hamano:
> 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>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-02-14 10:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-03 21:42 [PATCH] gitweb: fix base url set if PATH_INFO is used, add a / at the end Daniel Abrecht
2023-02-06 22:02 ` Junio C Hamano
2023-02-09 22:26 ` [PATCH v2] " Daniel Abrecht
2023-02-09 23:05 ` Junio C Hamano
2023-02-14 10:15 ` Daniel Abrecht
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).