]> Cypherpunks repositories - gostls13.git/commitdiff
mime: re-accept empty encoded-text
authorHiroshi Ioka <hirochachacha@gmail.com>
Sat, 8 Apr 2017 04:16:26 +0000 (13:16 +0900)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 29 Apr 2017 04:14:36 +0000 (04:14 +0000)
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>
src/mime/encodedword.go
src/mime/encodedword_test.go

index 158feaad4fd4a539ded8fc6c460b766b601be8de..99eb432f54e172dcf65c9a5a54ba45a869f26c5b 100644 (file)
@@ -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]
index b63fe043eda5efaa63d2e7bcffcb00674ab36401..6c54e502adb0ce99280868c5d318bd6a0a72a1a3 100644 (file)
@@ -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 {