1
0
mirror of https://github.com/golang/go synced 2024-11-19 03:14:42 -07:00

mime/quotedprintable: accept badly encoded bytes

RFC 2045 says:
    An "=" followed by two hexadecimal digits, one or both
    of which are lowercase letters in "abcdef", is formally
    illegal. A robust implementation might choose to
    recognize them as the corresponding uppercase letters.

    https://tools.ietf.org/html/rfc2045#page-22

Change-Id: Ibb4b1e4b8bf4fa65ff895ba486a931d90308bf70
Reviewed-on: https://go-review.googlesource.com/7891
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Alexandre Cesaro 2015-03-20 12:22:49 +01:00 committed by Brad Fitzpatrick
parent 8fc73a39ef
commit cf68fac7e7
2 changed files with 4 additions and 1 deletions

View File

@ -36,6 +36,9 @@ func fromHex(b byte) (byte, error) {
return b - '0', nil return b - '0', nil
case b >= 'A' && b <= 'F': case b >= 'A' && b <= 'F':
return b - 'A' + 10, nil return b - 'A' + 10, nil
// Accept badly encoded bytes.
case b >= 'a' && b <= 'f':
return b - 'a' + 10, nil
} }
return 0, fmt.Errorf("quotedprintable: invalid hex byte 0x%02x", b) return 0, fmt.Errorf("quotedprintable: invalid hex byte 0x%02x", b)
} }

View File

@ -27,10 +27,10 @@ func TestReader(t *testing.T) {
{in: "", want: ""}, {in: "", want: ""},
{in: "foo bar", want: "foo bar"}, {in: "foo bar", want: "foo bar"},
{in: "foo bar=3D", want: "foo bar="}, {in: "foo bar=3D", want: "foo bar="},
{in: "foo bar=3d", want: "foo bar="}, // lax.
{in: "foo bar=\n", want: "foo bar"}, {in: "foo bar=\n", want: "foo bar"},
{in: "foo bar\n", want: "foo bar\n"}, // somewhat lax. {in: "foo bar\n", want: "foo bar\n"}, // somewhat lax.
{in: "foo bar=0", want: "foo bar", err: io.ErrUnexpectedEOF}, {in: "foo bar=0", want: "foo bar", err: io.ErrUnexpectedEOF},
{in: "foo bar=ab", want: "foo bar", err: "quotedprintable: invalid hex byte 0x61"},
{in: "foo bar=0D=0A", want: "foo bar\r\n"}, {in: "foo bar=0D=0A", want: "foo bar\r\n"},
{in: " A B \r\n C ", want: " A B\r\n C"}, {in: " A B \r\n C ", want: " A B\r\n C"},
{in: " A B =\r\n C ", want: " A B C"}, {in: " A B =\r\n C ", want: " A B C"},