Skip to content

Commit

Permalink
mime: re-accept empty encoded-text
Browse files Browse the repository at this point in the history
https://go-review.googlesource.com/37812 prohibits empty encoded-text.
This CL accepts it again for backward compatibility.

Change-Id: I0e0840b501927f147160b999bb59d2d029ea314c
Reviewed-on: https://go-review.googlesource.com/40051
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
hirochachacha authored and bradfitz committed Apr 29, 2017
1 parent 38fbada commit b225396
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/mime/encodedword.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ type WordDecoder struct {

// Decode decodes an RFC 2047 encoded-word.
func (d *WordDecoder) Decode(word string) (string, error) {
// See https://tools.ietf.org/html/rfc2047#section-2
if len(word) < 9 || !strings.HasPrefix(word, "=?") || !strings.HasSuffix(word, "?=") || strings.Count(word, "?") != 4 {
// See https://tools.ietf.org/html/rfc2047#section-2 for details.
// Our decoder is permissive, we accept empty encoded-text.
if len(word) < 8 || !strings.HasPrefix(word, "=?") || !strings.HasSuffix(word, "?=") || strings.Count(word, "?") != 4 {
return "", errInvalidWord
}
word = word[2 : len(word)-2]
Expand All @@ -208,7 +209,7 @@ func (d *WordDecoder) Decode(word string) (string, error) {
if len(charset) == 0 {
return "", errInvalidWord
}
if len(word) <= split+3 {
if len(word) < split+3 {
return "", errInvalidWord
}
encoding := word[split+1]
Expand Down
2 changes: 1 addition & 1 deletion src/mime/encodedword_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func TestDecodeWord(t *testing.T) {
{"=?UTF-8?Q?=A?=", "", true},
{"=?UTF-8?A?A?=", "", true},
{"=????=", "", true},
{"=?UTF-8?Q??=", "", true},
{"=?UTF-8???=", "", true},
{"=?UTF-8?Q??=", "", false},
}

for _, test := range tests {
Expand Down

0 comments on commit b225396

Please sign in to comment.