From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 9A5011F461 for ; Sun, 26 Nov 2023 14:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701008373; bh=4vXO5oB05mdYSAPfhg74OHEVWYy5V7eJsd46oohcvJM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fNFI9X1F9tTNVMc3ErUPxzLuZyjieuq8Z61U35nmR+h6OEBpPjsnuJ5nXRk1iFflJ wOIFDuAcHhhBmqt6B7TlHSqzMXb/jYpVWv2JrB03i+sCv722rSw1cY4nOkUQ80uxTa abzMbYA3r6UuEVRkQvXlFC9xZOkP3lCSihHg/zas= From: Eric Wong To: spew@80x24.org Subject: [PATCH 3/7] hval: relative paths Date: Sun, 26 Nov 2023 14:19:29 +0000 Message-ID: <20231126141933.593525-3-e@80x24.org> In-Reply-To: <20231126141933.593525-1-e@80x24.org> References: <20231126141933.593525-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- lib/PublicInbox/Hval.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index e9b9ae64..93848d11 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,14 @@ 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 '/') { + File::Spec->abs2rel("/$u", $env->{PATH_INFO}); + } else { + $u; + } } # for misguided people who believe in this stuff, give them a