Commit 228b4416 authored by Ian Lance Taylor's avatar Ian Lance Taylor

mime/quotedprintable: accept bytes >= 0x80

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/121095Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b7498450
......@@ -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)
}
......
......@@ -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
......
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