diff options
Diffstat (limited to 'gcc-4.8/libgo/go/mime/multipart/quotedprintable.go')
-rw-r--r-- | gcc-4.8/libgo/go/mime/multipart/quotedprintable.go | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/gcc-4.8/libgo/go/mime/multipart/quotedprintable.go b/gcc-4.8/libgo/go/mime/multipart/quotedprintable.go index 0a60a6ed5..9ff4ee703 100644 --- a/gcc-4.8/libgo/go/mime/multipart/quotedprintable.go +++ b/gcc-4.8/libgo/go/mime/multipart/quotedprintable.go @@ -3,6 +3,10 @@ // license that can be found in the LICENSE file. // The file define a quoted-printable decoder, as specified in RFC 2045. +// Deviations: +// 1. in addition to "=\r\n", "=\n" is also treated as soft line break. +// 2. it will pass through a '\r' or '\n' not preceded by '=', consistent +// with other broken QP encoders & decoders. package multipart @@ -57,6 +61,12 @@ func isQPDiscardWhitespace(r rune) bool { return false } +var ( + crlf = []byte("\r\n") + lf = []byte("\n") + softSuffix = []byte("=") +) + func (q *qpReader) Read(p []byte) (n int, err error) { for len(p) > 0 { if len(q.line) == 0 { @@ -64,15 +74,29 @@ func (q *qpReader) Read(p []byte) (n int, err error) { return n, q.rerr } q.line, q.rerr = q.br.ReadSlice('\n') - q.line = bytes.TrimRightFunc(q.line, isQPDiscardWhitespace) - continue - } - if len(q.line) == 1 && q.line[0] == '=' { - // Soft newline; skipped. - q.line = nil + + // Does the line end in CRLF instead of just LF? + hasLF := bytes.HasSuffix(q.line, lf) + hasCR := bytes.HasSuffix(q.line, crlf) + wholeLine := q.line + q.line = bytes.TrimRightFunc(wholeLine, isQPDiscardWhitespace) + if bytes.HasSuffix(q.line, softSuffix) { + rightStripped := wholeLine[len(q.line):] + q.line = q.line[:len(q.line)-1] + if !bytes.HasPrefix(rightStripped, lf) && !bytes.HasPrefix(rightStripped, crlf) { + q.rerr = fmt.Errorf("multipart: invalid bytes after =: %q", rightStripped) + } + } else if hasLF { + if hasCR { + q.line = append(q.line, '\r', '\n') + } else { + q.line = append(q.line, '\n') + } + } continue } b := q.line[0] + switch { case b == '=': b, err = q.readHexByte(q.line[1:]) @@ -80,7 +104,9 @@ func (q *qpReader) Read(p []byte) (n int, err error) { return n, err } q.line = q.line[2:] // 2 of the 3; other 1 is done below - case b != '\t' && (b < ' ' || b > '~'): + case b == '\t' || b == '\r' || b == '\n': + break + case b < ' ' || b > '~': return n, fmt.Errorf("multipart: invalid unescaped byte 0x%02x in quoted-printable body", b) } p[0] = b |