unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] URIimap: canonicalize uppercases UIDVALIDITY parameter
@ 2021-04-26 11:44 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-04-26 11:44 UTC (permalink / raw)
  To: meta

And the UID one, too, as well.  This simplifies future
comparison and matching code once case is no longer
taken into account.
---
 lib/PublicInbox/URIimap.pm | 3 +++
 t/uri_imap.t               | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/lib/PublicInbox/URIimap.pm b/lib/PublicInbox/URIimap.pm
index dc193468..df9f5fd9 100644
--- a/lib/PublicInbox/URIimap.pm
+++ b/lib/PublicInbox/URIimap.pm
@@ -30,6 +30,9 @@ sub canonical {
 	my ($scheme, $auth, $path, $query, $_frag) = uri_split($$self);
 	$path =~ s!\A/+!/!; # excessive leading slash
 
+	# upper-case uidvalidity= and uid= parameter names
+	$path =~ s/;([^=]+)=([^;]*)/;\U$1\E=$2/g;
+
 	# lowercase the host portion
 	$auth =~ s#\A(.*@)?(.*?)(?::([0-9]+))?\z#
 		my $ret = ($1//'').lc($2);
diff --git a/t/uri_imap.t b/t/uri_imap.t
index e2aadf84..ed24fc1b 100644
--- a/t/uri_imap.t
+++ b/t/uri_imap.t
@@ -79,7 +79,11 @@ is($uri->uidvalidity(2), 2, 'iuid set');
 is($$uri, 'imap://0/mmm;UIDVALIDITY=2', 'uidvalidity appended');
 is($uri->iuid, undef, 'no iuid');
 
+is(PublicInbox::URIimap->new('imap://0/x;uidvalidity=1')->canonical->as_string,
+	'imap://0/x;UIDVALIDITY=1', 'capitalized UIDVALIDITY');
+
 $uri = PublicInbox::URIimap->new('imap://0/mmm/;uid=8');
+is($uri->canonical->as_string, 'imap://0/mmm/;UID=8', 'canonicalized UID');
 is($uri->mailbox, 'mmm', 'mailbox works with iuid');
 is($uri->iuid, 8, 'iuid extracted');
 is($uri->iuid(9), 9, 'iuid set');
@@ -93,4 +97,8 @@ is($$uri, 'imap://0/mmm;UIDVALIDITY=4/;UID=9',
 is($uri->iuid(3), 3, 'iuid set with uidvalidity');
 is($$uri, 'imap://0/mmm;UIDVALIDITY=4/;UID=3', 'iuid replaced properly');
 
+my $lc = lc($$uri);
+is(PublicInbox::URIimap->new($lc)->canonical->as_string, "$$uri",
+	'canonical uppercased both params');
+
 done_testing;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-26 11:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26 11:44 [PATCH] URIimap: canonicalize uppercases UIDVALIDITY parameter Eric Wong

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