Commit 2bafbe11 authored by Russ Cox's avatar Russ Cox

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/32176Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 07e72666
...@@ -346,6 +346,9 @@ func (p *addrParser) consumeAddrSpec() (spec string, err error) { ...@@ -346,6 +346,9 @@ func (p *addrParser) consumeAddrSpec() (spec string, err error) {
// quoted-string // quoted-string
debug.Printf("consumeAddrSpec: parsing quoted-string") debug.Printf("consumeAddrSpec: parsing quoted-string")
localPart, err = p.consumeQuotedString() localPart, err = p.consumeQuotedString()
if localPart == "" {
err = errors.New("mail: empty quoted string in addr-spec")
}
} else { } else {
// dot-atom // dot-atom
debug.Printf("consumeAddrSpec: parsing dot-atom") debug.Printf("consumeAddrSpec: parsing dot-atom")
...@@ -463,9 +466,6 @@ Loop: ...@@ -463,9 +466,6 @@ Loop:
i += size i += size
} }
p.s = p.s[i+1:] p.s = p.s[i+1:]
if len(qsb) == 0 {
return "", errors.New("mail: empty quoted-string")
}
return string(qsb), nil return string(qsb), nil
} }
......
...@@ -315,6 +315,16 @@ func TestAddressParsing(t *testing.T) { ...@@ -315,6 +315,16 @@ func TestAddressParsing(t *testing.T) {
}, },
}, },
}, },
// Issue 14866
{
`"" <emptystring@example.com>`,
[]*Address{
{
Name: "",
Address: "emptystring@example.com",
},
},
},
} }
for _, test := range tests { for _, test := range tests {
if len(test.exp) == 1 { if len(test.exp) == 1 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment