forked from golang/go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/mail: use base64 encoding when needed in Address.String()
When the name of an Address contains non-ASCII characters, Address.String() used mime.QEncoding to encode the name. However certain characters are forbidden when an encoded-word is in a phrase context (see RFC 2047 section 5.3) and these characters are not encoded by mime.QEncoding. In this case we now use mime.BEncoding (base64 encoding) so that forbidden characters are also encoded. Fixes golang#11292 Change-Id: I52db98b41ece439295e97d7e94c8190426f499c2 Reviewed-on: https://go-review.googlesource.com/16012 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
- Loading branch information
1 parent
b64b3a7
commit 2cb265d
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,6 +499,10 @@ func TestAddressFormatting(t *testing.T) { | |
&Address{Name: "Rob", Address: "@"}, | ||
`"Rob" <@>`, | ||
}, | ||
{ | ||
&Address{Name: "Böb, Jacöb", Address: "[email protected]"}, | ||
`=?utf-8?b?QsO2YiwgSmFjw7Zi?= <[email protected]>`, | ||
}, | ||
} | ||
for _, test := range tests { | ||
s := test.addr.String() | ||
|
@@ -594,3 +598,32 @@ func TestAddressParsingAndFormatting(t *testing.T) { | |
} | ||
|
||
} | ||
|
||
func TestAddressFormattingAndParsing(t *testing.T) { | ||
tests := []*Address{ | ||
&Address{Name: "@lïce", Address: "[email protected]"}, | ||
&Address{Name: "Böb O'Connor", Address: "[email protected]"}, | ||
&Address{Name: "???", Address: "[email protected]"}, | ||
&Address{Name: "Böb ???", Address: "[email protected]"}, | ||
&Address{Name: "Böb (Jacöb)", Address: "[email protected]"}, | ||
&Address{Name: "à#$%&'(),.:;<>@[]^`{|}~'", Address: "[email protected]"}, | ||
// https://golang.org/issue/11292 | ||
&Address{Name: "\"\\\x1f,\"", Address: "0@0"}, | ||
// https://golang.org/issue/12782 | ||
&Address{Name: "naé, mée", Address: "[email protected]"}, | ||
} | ||
|
||
for _, test := range tests { | ||
parsed, err := ParseAddress(test.String()) | ||
if err != nil { | ||
t.Errorf("ParseAddr(%q) error: %v", test.String(), err) | ||
continue | ||
} | ||
if parsed.Name != test.Name { | ||
t.Errorf("Parsed name = %q; want %q", parsed.Name, test.Name) | ||
} | ||
if parsed.Address != test.Address { | ||
t.Errorf("Parsed address = %q; want %q", parsed.Address, test.Address) | ||
} | ||
} | ||
} |