user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] lei_external: don't treat IPv6 URLs as globs
Date: Thu, 25 Feb 2021 05:37:17 +0600	[thread overview]
Message-ID: <20210224233718.19007-2-e@80x24.org> (raw)
In-Reply-To: <20210224233718.19007-1-e@80x24.org>

IPv6 addresses are hexadecimals and colons inside brackets, so
add some DWIM-ery to ensure we don't attempt to treat addresses
like "http://[dead:beef]/foo/" as a glob.
---
 lib/PublicInbox/LeiExternal.pm | 8 +++++++-
 t/lei_external.t               | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index 0cc84cca..47791d4e 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -54,6 +54,12 @@ sub glob2re {
 	my $p = '';
 	my $in_bracket = 0;
 	my $qm = 0;
+	my $schema_host_port = '';
+
+	# don't glob URL-looking things that look like IPv6
+	if ($re =~ s!\A([a-z0-9\+]+://\[[a-f0-9\:]+\](?::[0-9]+)?/)!!i) {
+		$schema_host_port = quotemeta $1; # "http://[::1]:1234"
+	}
 	my $changes = ($re =~ s!(.)!
 		$re_map{$p eq '\\' ? '' : do {
 			if ($1 eq '[') { ++$in_bracket }
@@ -69,7 +75,7 @@ sub glob2re {
 			(my $in_braces = $2) =~ tr!,!|!;
 			$1."($in_braces)";
 			/sge);
-	($changes - $qm) ? $re : undef;
+	($changes - $qm) ? $schema_host_port.$re : undef;
 }
 
 # get canonicalized externals list matching $loc
diff --git a/t/lei_external.t b/t/lei_external.t
index 78f71658..51d0af5c 100644
--- a/t/lei_external.t
+++ b/t/lei_external.t
@@ -17,6 +17,7 @@ is($canon->('/this//path/'), '/this/path', 'extra slashes gone');
 is($canon->('/ALL/CAPS'), '/ALL/CAPS', 'caps preserved');
 
 my $glob2re = $cls->can('glob2re');
+is($glob2re->('http://[::1]:1234/foo/'), undef, 'IPv6 URL not globbed');
 is($glob2re->('foo'), undef, 'plain string unchanged');
 is_deeply($glob2re->('[f-o]'), '[f-o]' , 'range accepted');
 is_deeply($glob2re->('*'), '[^/]*?' , 'wildcard accepted');

  reply	other threads:[~2021-02-24 23:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 23:37 [PATCH 0/2] "lei q" remote memoization Eric Wong
2021-02-24 23:37 ` Eric Wong [this message]
2021-02-24 23:37 ` [PATCH 2/2] lei q: auto-memoize remote messages into lei/store 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

  List information: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20210224233718.19007-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH 1/2] lei_external: don'\''t treat IPv6 URLs as globs' \
    /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

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

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