dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 3/7] hval: relative paths
Date: Sun, 26 Nov 2023 14:19:29 +0000	[thread overview]
Message-ID: <20231126141933.593525-3-e@80x24.org> (raw)
In-Reply-To: <20231126141933.593525-1-e@80x24.org>

---
 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

  parent reply	other threads:[~2023-11-26 14:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-26 14:19 [PATCH 1/7] WIP-cidx-xh-split Eric Wong
2023-11-26 14:19 ` [PATCH 2/7] WIP-cidx Eric Wong
2023-11-26 14:19 ` Eric Wong [this message]
2023-11-26 14:19 ` [PATCH 4/7] www_coderepo: load and use cindex join data Eric Wong
2023-11-26 14:19 ` [PATCH 5/7] cindex: require `-g GIT_DIR' or `-r PROJECT_ROOT' Eric Wong
2023-11-26 14:19 ` [PATCH 6/7] git: speed up ->git_path for non-worktrees Eric Wong
2023-11-26 14:19 ` [PATCH 7/7] cindex: set -cfg_f field unconditionally for --show Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231126141933.593525-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).