unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] URIimap: canonicalize uppercases UIDVALIDITY parameter
Date: Mon, 26 Apr 2021 11:44:25 +0000	[thread overview]
Message-ID: <20210426114425.14819-1-e@80x24.org> (raw)

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;

                 reply	other threads:[~2021-04-26 11:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210426114425.14819-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.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).