Skip to content

Commit

Permalink
net/mail: allow empty quoted string name in address again
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rsc committed Oct 27, 2016
1 parent 07e7266 commit 2bafbe1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/net/mail/message.go
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions src/net/mail/message_test.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 2bafbe1

Please sign in to comment.