]> Cypherpunks repositories - gostls13.git/commitdiff
net/mail: allow empty quoted string name in address again
authorRuss Cox <rsc@golang.org>
Wed, 26 Oct 2016 20:48:53 +0000 (16:48 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 27 Oct 2016 17:54:39 +0000 (17:54 +0000)
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>
src/net/mail/message.go
src/net/mail/message_test.go

index b1d526bba947f2a592872088ec98512eb1457d79..aa3a3e78c4ef4905ce8c0b1162a3849fcfa89ca8 100644 (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
 }
 
index b29e375f2e52535f50bd3b777c242c33dbd783db..f0761ab09fba75dffd6bb4b9b360f135e07952cf 100644 (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 {