Commit ef2c4865 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

mime/multipart: check for quoted-printable case insensitively

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: 's avatarIan Lance Taylor <iant@golang.org>
parent 8ebc9fbc
......@@ -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)
}
......
......@@ -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 {
......
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