]> Cypherpunks repositories - gostls13.git/commitdiff
mime/quotedprintable: accept bytes >= 0x80
authorIan Lance Taylor <iant@golang.org>
Wed, 27 Jun 2018 00:14:43 +0000 (17:14 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 27 Jun 2018 17:00:08 +0000 (17:00 +0000)
RFC 2045 doesn't permit non-ASCII bytes, but some systems send them
anyhow. With this change, we accept them. This does make it harder to
validate quotedprintable data, but on balance this seems like the best
approach given the existence of systems that generate invalid data.

Fixes #22597

Change-Id: I9f80f90a60b76ada2b5dea658b8dc8aace56cdbd
Reviewed-on: https://go-review.googlesource.com/121095
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/mime/quotedprintable/reader.go
src/mime/quotedprintable/reader_test.go

index b14224034307b480c1e6bcb98fc710075d2efebe..4239625402a2f79fcbaafcadae7d7ba2ade1db0c 100644 (file)
@@ -123,6 +123,10 @@ func (r *Reader) Read(p []byte) (n int, err error) {
                        r.line = r.line[2:] // 2 of the 3; other 1 is done below
                case b == '\t' || b == '\r' || b == '\n':
                        break
+               case b >= 0x80:
+                       // As an extension to RFC 2045, we accept
+                       // values >= 0x80 without complaint. Issue 22597.
+                       break
                case b < ' ' || b > '~':
                        return n, fmt.Errorf("quotedprintable: invalid unescaped byte 0x%02x in body", b)
                }
index ca016f969a4c1a62ebb7de9ce6a9007f7ae08b64..f870bdaa8dfcbdfe5f8534b372b4edb09abb3bfe 100644 (file)
@@ -37,7 +37,7 @@ func TestReader(t *testing.T) {
                {in: " A B =\n C ", want: " A B  C"}, // lax. treating LF as CRLF
                {in: "foo=\nbar", want: "foobar"},
                {in: "foo\x00bar", want: "foo", err: "quotedprintable: invalid unescaped byte 0x00 in body"},
-               {in: "foo bar\xff", want: "foo bar", err: "quotedprintable: invalid unescaped byte 0xff in body"},
+               {in: "foo bar\xff", want: "foo bar\xff"},
 
                // Equal sign.
                {in: "=3D30\n", want: "=30\n"},
@@ -65,6 +65,8 @@ func TestReader(t *testing.T) {
                // Example from RFC 2045:
                {in: "Now's the time =\n" + "for all folk to come=\n" + " to the aid of their country.",
                        want: "Now's the time for all folk to come to the aid of their country."},
+               {in: "accept UTF-8 right quotation mark: ’",
+                       want: "accept UTF-8 right quotation mark: ’"},
        }
        for _, tt := range tests {
                var buf bytes.Buffer