Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mime/quotedprintable: accept LWSP-char after = #70951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mime/quotedprintable/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var (
crlf = []byte("\r\n")
lf = []byte("\n")
softSuffix = []byte("=")
lwspChar = " \t"
)

// Read reads and decodes quoted-printable data from the underlying reader.
Expand All @@ -92,7 +93,7 @@ func (r *Reader) Read(p []byte) (n int, err error) {
wholeLine := r.line
r.line = bytes.TrimRightFunc(wholeLine, isQPDiscardWhitespace)
if bytes.HasSuffix(r.line, softSuffix) {
rightStripped := wholeLine[len(r.line):]
rightStripped := bytes.TrimLeft(wholeLine[len(r.line):], lwspChar)
r.line = r.line[:len(r.line)-1]
if !bytes.HasPrefix(rightStripped, lf) && !bytes.HasPrefix(rightStripped, crlf) &&
!(len(rightStripped) == 0 && len(r.line) > 0 && r.rerr == io.EOF) {
Expand Down
14 changes: 9 additions & 5 deletions src/mime/quotedprintable/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func TestReader(t *testing.T) {
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: ’"},

// Transport padding
{in: "foo= \r\nbar", want: "foobar"},
{in: "foo=\t \r\nbar", want: "foobar"},
}
for _, tt := range tests {
var buf strings.Builder
Expand Down Expand Up @@ -199,13 +203,13 @@ func TestExhaustive(t *testing.T) {
}
slices.Sort(outcomes)
got := strings.Join(outcomes, "\n")
want := `OK: 28934
invalid bytes after =: 3949
quotedprintable: invalid hex byte 0x0d: 2048
want := `OK: 30638
invalid bytes after =: 2243
quotedprintable: invalid hex byte 0x0d: 2050
unexpected EOF: 194`
if testing.Short() {
want = `OK: 896
invalid bytes after =: 100
want = `OK: 935
invalid bytes after =: 61
quotedprintable: invalid hex byte 0x0d: 26
unexpected EOF: 3`
}
Expand Down