From 69ae87044ca499aa401c73a9a1d764013539fb2d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 14 Dec 2019 01:02:56 +0000 Subject: address: use Email::Address::XS if available Email::Address::XS is a dependency of modern versions of Email::MIME, so it's likely loaded and installed on newer systems, already; and capable of handling more corner-cases than our pure-Perl fallback. We still fallback to the imperfect-but-good-enough-in-practice pure-Perl code while avoiding the non-XS Email::Address (which was susceptible to DoS attacks (CVE-2015-7686)). We just need to keep "git fast-import" happy. --- t/address.t | 67 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 26 deletions(-) (limited to 't') diff --git a/t/address.t b/t/address.t index 2a287102..e7c0d6a8 100644 --- a/t/address.t +++ b/t/address.t @@ -5,34 +5,49 @@ use warnings; use Test::More; use_ok 'PublicInbox::Address'; -is_deeply([qw(e@example.com e@example.org)], - [PublicInbox::Address::emails('User , e@example.org')], - 'address extraction works as expected'); - -is_deeply(['user@example.com'], - [PublicInbox::Address::emails('')], - 'comment after domain accepted before >'); - -my @names = PublicInbox::Address::names( - 'User , e@e, "John A. Doe" , , (xyz), '. - 'U Ser (do not use)'); -is_deeply(\@names, ['User', 'e', 'John A. Doe', 'x', 'xyz', 'U Ser'], - 'name extraction works as expected'); - -@names = PublicInbox::Address::names('"user@example.com" '); -is_deeply(['user'], \@names, 'address-as-name extraction works as expected'); - - -{ - my $backwards = 'u@example.com (John Q. Public)'; - @names = PublicInbox::Address::names($backwards); - is_deeply(\@names, ['John Q. Public'], 'backwards name OK'); - my @emails = PublicInbox::Address::emails($backwards); - is_deeply(\@emails, ['u@example.com'], 'backwards emails OK'); +sub test_pkg { + my ($pkg) = @_; + my $emails = \&{"${pkg}::emails"}; + my $names = \&{"${pkg}::names"}; + + is_deeply([qw(e@example.com e@example.org)], + [$emails->('User , e@example.org')], + 'address extraction works as expected'); + + is_deeply(['user@example.com'], + [$emails->('')], + 'comment after domain accepted before >'); + + my @names = $names->( + 'User , e@e, "John A. Doe" , , (xyz), '. + 'U Ser (do not use)'); + is_deeply(\@names, ['User', 'e', 'John A. Doe', 'x', 'xyz', 'U Ser'], + 'name extraction works as expected'); + + @names = $names->('"user@example.com" '); + is_deeply(['user'], \@names, + 'address-as-name extraction works as expected'); + + { + my $backwards = 'u@example.com (John Q. Public)'; + @names = $names->($backwards); + is_deeply(\@names, ['John Q. Public'], 'backwards name OK'); + my @emails = $emails->($backwards); + is_deeply(\@emails, ['u@example.com'], 'backwards emails OK'); + } + + @names = $names->('"Quote Unneeded" '); + is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped'); } +test_pkg('PublicInbox::Address'); -@names = PublicInbox::Address::names('"Quote Unneeded" '); -is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped'); +SKIP: { + if ($INC{'PublicInbox/AddressPP.pm'}) { + skip 'Email::Address::XS missing', 8; + } + use_ok 'PublicInbox::AddressPP'; + test_pkg('PublicInbox::AddressPP'); +} done_testing; -- cgit v1.2.3-24-ge0c7