1
0
mirror of https://github.com/golang/go synced 2024-09-30 09:18:35 -06:00

net/mail: allow empty quoted string name in address again

CL 12905 disallowed "Bob" <""@example.com> but inadvertently
also disallowed "" <bob@example.com>. Move the empty string
check to apply only in the addr-spec.

Fixes #14866.

Change-Id: Ia0b7a1a32810aa78157ae77bd0130b78154c460d
Reviewed-on: https://go-review.googlesource.com/32176
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Russ Cox 2016-10-26 16:48:53 -04:00
parent 07e72666ec
commit 2bafbe11b1
2 changed files with 13 additions and 3 deletions

View File

@ -346,6 +346,9 @@ func (p *addrParser) consumeAddrSpec() (spec string, err error) {
// quoted-string
debug.Printf("consumeAddrSpec: parsing quoted-string")
localPart, err = p.consumeQuotedString()
if localPart == "" {
err = errors.New("mail: empty quoted string in addr-spec")
}
} else {
// dot-atom
debug.Printf("consumeAddrSpec: parsing dot-atom")
@ -463,9 +466,6 @@ Loop:
i += size
}
p.s = p.s[i+1:]
if len(qsb) == 0 {
return "", errors.New("mail: empty quoted-string")
}
return string(qsb), nil
}

View File

@ -315,6 +315,16 @@ func TestAddressParsing(t *testing.T) {
},
},
},
// Issue 14866
{
`"" <emptystring@example.com>`,
[]*Address{
{
Name: "",
Address: "emptystring@example.com",
},
},
},
}
for _, test := range tests {
if len(test.exp) == 1 {