Commit 971459e8 authored by Russ Cox's avatar Russ Cox

net/textproto: fix build

R=bradfitz
CC=golang-dev
https://golang.org/cl/4815041
parent 27a3dcd0
...@@ -141,14 +141,14 @@ func testMultipart(t *testing.T, r io.Reader, onlyNewlines bool) { ...@@ -141,14 +141,14 @@ func testMultipart(t *testing.T, r io.Reader, onlyNewlines bool) {
t.Error("Expected part1") t.Error("Expected part1")
return return
} }
if part.Header.Get("Header1") != "value1" { if x := part.Header.Get("Header1"); x != "value1" {
t.Error("Expected Header1: value") t.Errorf("part.Header.Get(%q) = %q, want %q", "Header1", x, "value1")
} }
if part.Header.Get("foo-bar") != "baz" { if x := part.Header.Get("foo-bar"); x != "baz" {
t.Error("Expected foo-bar: baz") t.Errorf("part.Header.Get(%q) = %q, want %q", "foo-bar", x, "baz")
} }
if part.Header.Get("Foo-Bar") != "baz" { if x := part.Header.Get("Foo-Bar"); x != "baz" {
t.Error("Expected Foo-Bar: baz") t.Errorf("part.Header.Get(%q) = %q, want %q", "Foo-Bar", x, "baz")
} }
buf.Reset() buf.Reset()
if _, err := io.Copy(buf, part); err != nil { if _, err := io.Copy(buf, part); err != nil {
......
...@@ -115,6 +115,13 @@ func (r *Reader) readContinuedLineSlice() ([]byte, os.Error) { ...@@ -115,6 +115,13 @@ func (r *Reader) readContinuedLineSlice() ([]byte, os.Error) {
} }
line = trim(line) line = trim(line)
copied := false
if r.R.Buffered() < 1 {
// ReadByte will flush the buffer; make a copy of the slice.
copied = true
line = append([]byte(nil), line...)
}
// Look for a continuation line. // Look for a continuation line.
c, err := r.R.ReadByte() c, err := r.R.ReadByte()
if err != nil { if err != nil {
...@@ -127,6 +134,11 @@ func (r *Reader) readContinuedLineSlice() ([]byte, os.Error) { ...@@ -127,6 +134,11 @@ func (r *Reader) readContinuedLineSlice() ([]byte, os.Error) {
return line, nil return line, nil
} }
if !copied {
// The next readLineSlice will invalidate the previous one.
line = append(make([]byte, 0, len(line)*2), line...)
}
// Read continuation lines. // Read continuation lines.
for { for {
// Consume leading spaces; one already gone. // Consume leading spaces; one already gone.
...@@ -140,9 +152,6 @@ func (r *Reader) readContinuedLineSlice() ([]byte, os.Error) { ...@@ -140,9 +152,6 @@ func (r *Reader) readContinuedLineSlice() ([]byte, os.Error) {
break break
} }
} }
// copy now since the next call to read a slice invalidates line
line = append(make([]byte, 0, len(line)*2), line...)
var cont []byte var cont []byte
cont, err = r.readLineSlice() cont, err = r.readLineSlice()
cont = trim(cont) cont = trim(cont)
......
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