Skip to contentSkip to conversation

gitweb: fix base url set if PATH_INFO is used, add a / at the end.

PATCH In review Daniel Abrecht 2 participants 2 messages Feb 3, 2023 – Feb 6, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitweb: fix base url set if PATH_INFO is used, add a / at the end.

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.

---
 gitweb/gitweb.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gitweb/gitweb.perl +1 -1
index e66eb3d9ba..acb2cce5f6 100755
@@ -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);
 
Signature · 1 line
2.39.0
#1 lore raw
Quoted 17 lines · Daniel Abrecht

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.

---
 gitweb/gitweb.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gitweb/gitweb.perl +0 -0
index e66eb3d9ba..acb2cce5f6 100755

gitweb/gitweb.perl sub git_header_html { · line 4220

Quoted 5 lines
gitweb/gitweb.perl +1 -1
@@ -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?