]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wwwstream: show relative coderepo URLs correctly
authorEric Wong <e@80x24.org>
Tue, 22 Dec 2020 05:04:16 +0000 (05:04 +0000)
committerEric Wong <e@80x24.org>
Tue, 22 Dec 2020 22:56:06 +0000 (22:56 +0000)
Trying to link "foo.git" relative to the current URL usually
does not provide correct results, so prefix it by going
into the parent directory if an absolute (or protocol-relative)
URL is not supplied.

lib/PublicInbox/WwwStream.pm

index 9ba8fa114de43a6c5621915f2e035d548fa348b9..958251a347d55edc89a8501773e325c90460749e 100644 (file)
@@ -81,13 +81,17 @@ sub coderepos ($) {
        my ($ctx) = @_;
        my $cr = $ctx->{ibx}->{coderepo} // return ();
        my $cfg = $ctx->{www}->{pi_cfg};
+       my $upfx = ($ctx->{-upfx} // ''). '../';
        my @ret;
        for my $cr_name (@$cr) {
                my $urls = $cfg->{"coderepo.$cr_name.cgiturl"} // next;
                $ret[0] //= <<EOF;
 code repositories for the project(s) associated with this inbox:
 EOF
-               for my $u (@$urls) {
+               for (@$urls) {
+                       # relative or absolute URL?, prefix relative "foo.git"
+                       # with appropriate number of "../"
+                       my $u = m!\A(?:[a-z\+]+:)?//! ? $_ : $upfx.$_;
                        $u = ascii_html(prurl($ctx->{env}, $u));
                        $ret[0] .= qq(\n\t<a\nhref="$u">$u</a>);
                }