From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 20A771F9FE for ; Wed, 24 Feb 2021 11:31:55 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/4] add PublicInbox::URInntps package Date: Wed, 24 Feb 2021 17:31:51 +0600 Message-Id: <20210224113154.686-2-e@80x24.org> In-Reply-To: <20210224113154.686-1-e@80x24.org> References: <20210224113154.686-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 +# License: AGPL-3.0+ + +# 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 +# License: AGPL-3.0+ +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;