From: Timmy Douglas Date: Sat, 1 Feb 2020 22:14:30 +0000 (+0000) Subject: net/mail: skip empty entries in parseAddressList X-Git-Tag: go1.15beta1~1159 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=30e3bf2051e1659ba7ea1d14849f79deb82a5606;p=gostls13.git net/mail: skip empty entries in parseAddressList RFC 5322 has a section 4.4 where it says that address-list could have "null" members: "That is, there could be two or more commas in such a list with nothing in between them, or commas at the beginning or end of the list." This change handles such a case so that mail clients using this method on actual email messages get a reasonable return value when they parse email. Fixes #36959 Change-Id: I3ca240969935067262e3d751d376a06db1fef2a2 GitHub-Last-Rev: b96a9f2c075dfd67c3ff7b8ae0c12e12035f0da0 GitHub-Pull-Request: golang/go#36966 Reviewed-on: https://go-review.googlesource.com/c/go/+/217377 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí --- diff --git a/src/net/mail/message.go b/src/net/mail/message.go index 0781310ed3..6833cfaec1 100644 --- a/src/net/mail/message.go +++ b/src/net/mail/message.go @@ -274,6 +274,15 @@ func (p *addrParser) parseAddressList() ([]*Address, error) { var list []*Address for { p.skipSpace() + + // allow skipping empty entries (RFC5322 obs-addr-list) + if p.consume(',') { + continue + } + if p.empty() { + break + } + addrs, err := p.parseAddress(true) if err != nil { return nil, err diff --git a/src/net/mail/message_test.go b/src/net/mail/message_test.go index acab538e18..75db767547 100644 --- a/src/net/mail/message_test.go +++ b/src/net/mail/message_test.go @@ -431,6 +431,20 @@ func TestAddressParsing(t *testing.T) { }, }, }, + // RFC5322 4.4 obs-addr-list + { + ` , joe@where.test,,John ,`, + []*Address{ + { + Name: "", + Address: "joe@where.test", + }, + { + Name: "John", + Address: "jdoe@one.test", + }, + }, + }, { `Group1: ;, Group 2: addr2@example.com;, John `, []*Address{