diff options
author | Eric Wong <e@80x24.org> | 2023-11-28 14:56:20 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-11-29 02:13:21 +0000 |
commit | 10b23966ff8fa35a112f7fe2b9386dd4967d818c (patch) | |
tree | 6a4cf8bbcb31eb708732833aef9b5b88fde7e679 /lib/PublicInbox | |
parent | 87b7f633f2414a76c55f84da73cd7dd43f964533 (diff) | |
download | public-inbox-10b23966ff8fa35a112f7fe2b9386dd4967d818c.tar.gz |
File::Spec->abs2rel doesn't touch the filesystem at all when given an absolute base arg ($env->{PATH_INFO}), so we can rely on it to generate relative links that work with the `mount' from Plack::Builder and also people running `wget -r' mirrors.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/Hval.pm | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index e9b9ae64..b804254a 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -13,6 +13,7 @@ our @EXPORT_OK = qw/ascii_html obfuscate_addrs to_filename src_escape to_attr prurl mid_href fmt_ts ts2str utf8_maybe/; use POSIX qw(strftime); my $enc_ascii = find_encoding('us-ascii'); +use File::Spec; # safe-ish acceptable filename pattern for portability our $FN = '[a-zA-Z0-9][a-zA-Z0-9_\-\.]+[a-zA-Z0-9]'; # needs \z anchor @@ -69,7 +70,16 @@ sub prurl ($$) { $u = $host_match[0] // $u->[0]; # fall through to below: } - index($u, '//') == 0 ? "$env->{'psgi.url_scheme'}:$u" : $u; + my $dslash = index($u, '//'); + if ($dslash == 0) { + "$env->{'psgi.url_scheme'}:$u" + } elsif ($dslash < 0 && substr($u, 0, 1) ne '/' && + substr(my $path = $env->{PATH_INFO}, 0, 1) eq '/') { + # this won't touch the FS at all: + File::Spec->abs2rel("/$u", $path); + } else { + $u; + } } # for misguided people who believe in this stuff, give them a |