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/4] add PublicInbox::URInntps package
Date: Wed, 24 Feb 2021 17:31:51 +0600	[thread overview]
Message-ID: <20210224113154.686-2-e@80x24.org> (raw)
In-Reply-To: <20210224113154.686-1-e@80x24.org>

We prefer the IANA-registered form of URIs to avoid confusing
users, but the URI package has yet to support it.

cf. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=983419
---
 MANIFEST                    |  2 ++
 lib/PublicInbox/URInntps.pm | 17 ++++++++++++++++
 t/uri_nntps.t               | 40 +++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+)
 create mode 100644 lib/PublicInbox/URInntps.pm
 create mode 100644 t/uri_nntps.t

diff --git a/MANIFEST b/MANIFEST
index 21e37678..9cf97563 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -243,6 +243,7 @@ lib/PublicInbox/TLS.pm
 lib/PublicInbox/TestCommon.pm
 lib/PublicInbox/Tmpfile.pm
 lib/PublicInbox/URIimap.pm
+lib/PublicInbox/URInntps.pm
 lib/PublicInbox/Unsubscribe.pm
 lib/PublicInbox/UserContent.pm
 lib/PublicInbox/V2Writable.pm
@@ -437,6 +438,7 @@ t/thread-cycle.t
 t/thread-index-gap.t
 t/time.t
 t/uri_imap.t
+t/uri_nntps.t
 t/utf8.eml
 t/v1-add-remove-add.t
 t/v1reindex.t
diff --git a/lib/PublicInbox/URInntps.pm b/lib/PublicInbox/URInntps.pm
new file mode 100644
index 00000000..69fe7163
--- /dev/null
+++ b/lib/PublicInbox/URInntps.pm
@@ -0,0 +1,17 @@
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# deal with the lack of URI::nntps in upstream URI.
+# nntps is IANA registered, snews is deprecated
+# cf. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=983419
+package PublicInbox::URInntps;
+use strict;
+use parent qw(URI::snews);
+use URI;
+
+sub new {
+	my ($class, $url) = @_;
+	$url =~ m!\Anntps://!i ? bless(\$url, $class) : URI->new($url);
+}
+
+1;
diff --git a/t/uri_nntps.t b/t/uri_nntps.t
new file mode 100644
index 00000000..babd8088
--- /dev/null
+++ b/t/uri_nntps.t
@@ -0,0 +1,40 @@
+#!perl -w
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict; use v5.10.1; use PublicInbox::TestCommon;
+require_mods 'URI';
+use_ok 'PublicInbox::URInntps';
+my $uri = PublicInbox::URInntps->new('nntp://EXAMPLE.com/inbox.test');
+isnt(ref($uri), 'PublicInbox::URInntps', 'URI fallback');
+is($uri->scheme, 'nntp', 'NNTP fallback ->scheme');
+
+$uri = PublicInbox::URInntps->new('nntps://EXAMPLE.com/inbox.test');
+is($uri->host, 'EXAMPLE.com', 'host matches');
+is($uri->canonical->host, 'example.com', 'host canonicalized');
+is($uri->canonical->as_string, 'nntps://example.com/inbox.test',
+	'URI canonicalized');
+is($uri->port, 563, 'nntps port');
+is($uri->userinfo, undef, 'no userinfo');
+is($uri->scheme, 'nntps', '->scheme works');
+is($uri->group, 'inbox.test', '->group works');
+
+$uri = PublicInbox::URInntps->new('nntps://foo@0/');
+is("$uri", $uri->as_string, '"" overload works');
+is($uri->host, '0', 'numeric host');
+is($uri->userinfo, 'foo', 'user extracted');
+
+$uri = PublicInbox::URInntps->new('nntps://ipv6@[::1]');
+is($uri->host, '::1', 'IPv6 host');
+is($uri->group, '', '->group is empty');
+
+$uri = PublicInbox::URInntps->new('nntps://0:666/INBOX.test');
+is($uri->port, 666, 'port read');
+is($uri->group, 'INBOX.test', 'group read after port');
+
+is(PublicInbox::URInntps->new('nntps://0:563/')->canonical->as_string,
+	'nntps://0/', 'default port stripped');
+
+$uri = PublicInbox::URInntps->new('nntps://NSA:Hunter2@0/inbox');
+is($uri->userinfo, 'NSA:Hunter2', 'userinfo accepted w/ pass');
+
+done_testing;

  reply	other threads:[~2021-02-24 11:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 11:31 [PATCH 0/4] lei <import|convert> nntp:// Eric Wong
2021-02-24 11:31 ` Eric Wong [this message]
2021-02-24 11:31 ` [PATCH 2/4] lei <import|convert>: support NNTP sources Eric Wong
2021-02-24 11:31 ` [PATCH 3/4] watch: switch IMAP and NNTP fetch loops to NetReader Eric Wong
2021-02-24 23:25   ` [SQUASH 5/4] net_reader: do not warn on EINTR if user quit Eric Wong
2021-02-24 11:31 ` [PATCH 4/4] net_reader: trim exports and remove unused uri_new 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=20210224113154.686-2-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.
Code repositories for project(s) associated with this public 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).