They're uncommon, fortunately, but we make no attempt to
handle nested comments (which would open us up to things
like CVE-2015-7686) or use the comment in place of a
missing name.
# very loose regexes, here. We don't need RFC-compliance,
# just enough to make thing sanely displayable and pass to git
-sub emails { ($_[0] =~ /([\w\.\+=\-]+\@[\w\.\-]+)>?\s*(?:,\s*|\z)/g) }
+sub emails {
+ ($_[0] =~ /([\w\.\+=\-]+\@[\w\.\-]+)>?\s*(?:\(.*?\))?(?:,\s*|\z)/g)
+}
sub names {
map {
$e = $_ =~ /\S/ ? $_ : $e;
$e =~ s/\@\S+\z//;
$e;
- } split(/\@+[\w\.\-]+>?\s*(?:,\s*|\z)/, $_[0]);
+ } split(/\@+[\w\.\-]+>?\s*(?:\(.*?\))?(?:,\s*|\z)/, $_[0]);
}
1;
@names = PublicInbox::Address::names('"user@example.com" <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, ['u'], 'backwards name OK');
+ my @emails = PublicInbox::Address::emails($backwards);
+ is_deeply(\@emails, ['u@example.com'], 'backwards emails OK');
+}
+
done_testing;