{"thread":{"id":"59221","subject":"Re: [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end","startedAt":"2023-02-09T23:05:29Z","lastAt":"2023-02-14T10:15:55Z","messageCount":2,"participants":["Junio C Hamano","Daniel Abrecht"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"471887","messageId":"xmqqfsbel9sf.fsf@gitster.g","threadId":"59221","inReplyTo":"20230209222648.z-sqdvWiK7xa-NLagt3B_X_4bFQJBsA8cA06YvgXqWQ@z","subject":"Re: [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-02-09T23:05:20Z","receivedAt":"2023-02-09T23:05:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Abrecht <git-git@nodmarc.danielabrecht.ch> writes:\n\n> In HTML, if there is a base tag like `<base href=\"/a/b\">`, a relative\n> URL like\n> `c/d` will be resolved by the browser as `a/c/d` and not as\n> `a/b/c/d`. But with\n> a base tag like `<base href=\"/a/b/\">` it will result in `a/b/c/d`.\n>\n> Signed-off-by: Daniel Abrecht <public@danielabrecht.ch>\n> ---\n>  gitweb/gitweb.perl | 5 +++++\n>  1 file changed, 5 insertions(+)\n>\n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index e66eb3d9ba..edcee1652c 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -74,6 +74,11 @@ sub evaluate_uri {\n>  \t\t}\n>  \t}\n>\n> +\t# $base_url is later used in the <base> tag as a URL, if it\n> doesn't end in a /\n\nIt seems an overlog line was wrapped around and broke the patch.\n\n> +\t# the browser will strip away the last component for relative URLs.\n> +\t# Add the / if it's missing.\n\nThe above is not an incorrect statement per-se, but if $base were\npointing at the document, we would likely break if we add an extra\nslash.  Don't we want to say something like \n\n\t# $base_url at this point points at a directory, not a\n        # single document, and later is used in the <base> tag.\n        # Make sure it ends in a '/'.  Otherwise, we'd lose the last\n        # component when forming a relative URL.\n\nperhaps?\n\n> +\t$base_url .= '/' if not $base_url =~ /\\/$/;\n> +\n>  \t# target of the home link on top of all pages\n>  \tour $home_link = $my_uri || \"/\";\n>  }\n"},{"id":"472054","messageId":"522571c427c937ef52bb69b88cb3dea1@nodmarc.danielabrecht.ch","threadId":"59221","inReplyTo":"xmqqfsbel9sf.fsf@gitster.g","subject":"Re: [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end","fromName":"Daniel Abrecht","fromEmail":"git-git@nodmarc.danielabrecht.ch","sentAt":"2023-02-14T10:15:44Z","receivedAt":"2023-02-14T10:15:55Z","isPatch":true,"sender":{"key":"git-git@nodmarc.danielabrecht.ch","avatar":null},"body":"Am 2023-02-10 00:05, schrieb Junio C Hamano:\n> Daniel Abrecht <git-git@nodmarc.danielabrecht.ch> writes:\n>> +\t# the browser will strip away the last component for relative URLs.\n>> +\t# Add the / if it's missing.\n> \n> The above is not an incorrect statement per-se, but if $base were\n> pointing at the document, we would likely break if we add an extra\n> slash.  Don't we want to say something like\n> \n> \t# $base_url at this point points at a directory, not a\n>         # single document, and later is used in the <base> tag.\n>         # Make sure it ends in a '/'.  Otherwise, we'd lose the last\n>         # component when forming a relative URL.\n> \n> perhaps?\n\nAfter thinking about this for a while, I realized that this isn't as \nsimple as I thought.\n\nI'm currently using apache and some rewrite rules so I can access \nprojects at /git/myproject.git/ (See my config below).\nSo in my case, $base_url is /git at this point, and I need to add a /.\n\nBut if I didn't have those rewrite rules, I could instead access the \nrepos using /git/gitweb.cgi/myproject.git/ .\nIn that case, $base_url would be /git/gitweb.cgi at this point, so it \ndoes refer to the script / document.\nThe assets are still at /git/ and not at /git/gitweb.cgi/, so links are \nrelative to /git/gitweb.cgi/ but assets are\nrelative to /git/. It seams relative URLs are only used for assets, so \nthe $base_url should really be /git/gitweb.cgi\nor alternatively just /git/ there, and just adding a slash would be \nwrong in that case.\n\nGiven this, I no longer think I should change the way it currently is.\nI will just override $base_url in my config file instead.\n\n\n\n<Macro gitweb $location>\n   SetEnv GITWEB_CONFIG /etc/gitweb.conf\n   SetEnv GIT_HTTP_EXPORT_ALL\n   ScriptAliasMatch \\\n   \"(?x)^/.*/(.*\\.git/(HEAD | \\\n       info/refs | \\\n       objects/(info/[^/]+ | \\\n          [0-9a-f]{2}/[0-9a-f]{38} | \\\n          pack/pack-[0-9a-f]{40}\\.(pack|idx)) | \\\n       git-(upload|receive)-pack))$\" \\\n   /usr/lib/git-core/git-http-backend/$1\n   Alias $location/ /usr/share/gitweb/\n   RewriteRule \n^$location/.*\\.git/(HEAD|info|objects|refs|git-(upload|receive)-pack) - \n[E=GIT_PROJECT_ROOT:%{DOCUMENT_ROOT}$location/,PT,END]\n   RewriteRule ^$location/(.*\\.git(/.*)?)?$ $location/gitweb.cgi/$1 \n[E=GIT_PROJECT_ROOT:%{DOCUMENT_ROOT}$location/,L,PT]\n   <Location $location>\n     Require all granted\n     AllowOverride None\n   </Location>\n   <Directory /usr/share/gitweb/>\n     Options +FollowSymLinks +ExecCGI\n     AddHandler cgi-script .cgi\n   </Directory>\n</Macro>\n\n<VirtualHost *:443>\n   Use VHostSSL projects.dpa.li\n   DocumentRoot /var/www/projects.dpa.li/\n   Use gitweb /git\n</VirtualHost>\n"}]}