]> Cypherpunks.ru repositories - gostls13.git/commitdiff
mime/multipart: check for quoted-printable case insensitively
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 8 Nov 2018 18:46:34 +0000 (18:46 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 9 Nov 2018 05:37:10 +0000 (05:37 +0000)
Fixes #28674

Change-Id: Id88e0a4b86b50eb45f0d968d7e4bbe66b7f37f82
Reviewed-on: https://go-review.googlesource.com/c/148579
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/mime/multipart/multipart.go
src/mime/multipart/multipart_test.go

index 0993fb7e91d5aa9a0e34e350732ca625715fc3f6..a222409d3ce6487ef9c4bb313acbd6912fbe7e9e 100644 (file)
@@ -21,6 +21,7 @@ import (
        "mime"
        "mime/quotedprintable"
        "net/textproto"
+       "strings"
 )
 
 var emptyParams = make(map[string]string)
@@ -135,7 +136,7 @@ func newPart(mr *Reader) (*Part, error) {
        }
        bp.r = partReader{bp}
        const cte = "Content-Transfer-Encoding"
-       if bp.Header.Get(cte) == "quoted-printable" {
+       if strings.EqualFold(bp.Header.Get(cte), "quoted-printable") {
                bp.Header.Del(cte)
                bp.r = quotedprintable.NewReader(bp.r)
        }
index 7bf606765ce9eea94f2872621bb1cf11f306e897..5a8102b82236c75da43e938297ce06da1d4f171c 100644 (file)
@@ -419,8 +419,16 @@ func TestLineContinuation(t *testing.T) {
 }
 
 func TestQuotedPrintableEncoding(t *testing.T) {
+       for _, cte := range []string{"quoted-printable", "Quoted-PRINTABLE"} {
+               t.Run(cte, func(t *testing.T) {
+                       testQuotedPrintableEncoding(t, cte)
+               })
+       }
+}
+
+func testQuotedPrintableEncoding(t *testing.T, cte string) {
        // From https://golang.org/issue/4411
-       body := "--0016e68ee29c5d515f04cedf6733\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nContent-Disposition: form-data; name=text\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nwords words words words words words words words words words words words wor=\r\nds words words words words words words words words words words words words =\r\nwords words words words words words words words words words words words wor=\r\nds words words words words words words words words words words words words =\r\nwords words words words words words words words words\r\n--0016e68ee29c5d515f04cedf6733\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nContent-Disposition: form-data; name=submit\r\n\r\nSubmit\r\n--0016e68ee29c5d515f04cedf6733--"
+       body := "--0016e68ee29c5d515f04cedf6733\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nContent-Disposition: form-data; name=text\r\nContent-Transfer-Encoding: " + cte + "\r\n\r\nwords words words words words words words words words words words words wor=\r\nds words words words words words words words words words words words words =\r\nwords words words words words words words words words words words words wor=\r\nds words words words words words words words words words words words words =\r\nwords words words words words words words words words\r\n--0016e68ee29c5d515f04cedf6733\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nContent-Disposition: form-data; name=submit\r\n\r\nSubmit\r\n--0016e68ee29c5d515f04cedf6733--"
        r := NewReader(strings.NewReader(body), "0016e68ee29c5d515f04cedf6733")
        part, err := r.NextPart()
        if err != nil {