mirror of
https://github.com/golang/go
synced 2024-11-17 18:14:46 -07:00
net/mail: return error on empty address list
This restores the handling accidentally changed in CL 217377. Fixes #40803 For #36959 Change-Id: If77fbc0c2a1dde4799f760affdfb8dde9bcaf458 Reviewed-on: https://go-review.googlesource.com/c/go/+/248598 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Jeremy Fishman <jfishman@cloudflare.com>
This commit is contained in:
parent
2aba467933
commit
3e636ab9ad
@ -279,9 +279,6 @@ func (p *addrParser) parseAddressList() ([]*Address, error) {
|
||||
if p.consume(',') {
|
||||
continue
|
||||
}
|
||||
if p.empty() {
|
||||
break
|
||||
}
|
||||
|
||||
addrs, err := p.parseAddress(true)
|
||||
if err != nil {
|
||||
@ -295,9 +292,17 @@ func (p *addrParser) parseAddressList() ([]*Address, error) {
|
||||
if p.empty() {
|
||||
break
|
||||
}
|
||||
if !p.consume(',') {
|
||||
if p.peek() != ',' {
|
||||
return nil, errors.New("mail: expected comma")
|
||||
}
|
||||
|
||||
// Skip empty entries for obs-addr-list.
|
||||
for p.consume(',') {
|
||||
p.skipSpace()
|
||||
}
|
||||
if p.empty() {
|
||||
break
|
||||
}
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
@ -445,6 +445,19 @@ func TestAddressParsing(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
` , joe@where.test,,John <jdoe@one.test>,,`,
|
||||
[]*Address{
|
||||
{
|
||||
Name: "",
|
||||
Address: "joe@where.test",
|
||||
},
|
||||
{
|
||||
Name: "John",
|
||||
Address: "jdoe@one.test",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
`Group1: <addr1@example.com>;, Group 2: addr2@example.com;, John <addr3@example.com>`,
|
||||
[]*Address{
|
||||
@ -1067,3 +1080,22 @@ func TestAddressFormattingAndParsing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyAddress(t *testing.T) {
|
||||
parsed, err := ParseAddress("")
|
||||
if parsed != nil || err == nil {
|
||||
t.Errorf(`ParseAddress("") = %v, %v, want nil, error`, parsed, err)
|
||||
}
|
||||
list, err := ParseAddressList("")
|
||||
if len(list) > 0 || err == nil {
|
||||
t.Errorf(`ParseAddressList("") = %v, %v, want nil, error`, list, err)
|
||||
}
|
||||
list, err = ParseAddressList(",")
|
||||
if len(list) > 0 || err == nil {
|
||||
t.Errorf(`ParseAddressList("") = %v, %v, want nil, error`, list, err)
|
||||
}
|
||||
list, err = ParseAddressList("a@b c@d")
|
||||
if len(list) > 0 || err == nil {
|
||||
t.Errorf(`ParseAddressList("") = %v, %v, want nil, error`, list, err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user