Commit b225396f authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Brad Fitzpatrick

mime: re-accept empty encoded-text

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 38fbada5
......@@ -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]
......@@ -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]
......
......@@ -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 {
......
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