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

mime/multipart: remove newline at top of the multipart.

R=golang-dev, bradfitz, arctanofyourface
CC=golang-dev
https://golang.org/cl/4635063
This commit is contained in:
Yasuhiro Matsumoto 2011-06-23 10:11:33 -07:00 committed by Brad Fitzpatrick
parent d847467041
commit 73d741fd5b
2 changed files with 12 additions and 1 deletions

View File

@ -61,7 +61,11 @@ func (w *Writer) CreatePart(header textproto.MIMEHeader) (io.Writer, os.Error) {
}
}
var b bytes.Buffer
fmt.Fprintf(&b, "\r\n--%s\r\n", w.boundary)
if w.lastpart != nil {
fmt.Fprintf(&b, "\r\n--%s\r\n", w.boundary)
} else {
fmt.Fprintf(&b, "--%s\r\n", w.boundary)
}
// TODO(bradfitz): move this to textproto.MimeHeader.Write(w), have it sort
// and clean, like http.Header.Write(w) does.
for k, vv := range header {

View File

@ -30,6 +30,13 @@ func TestWriter(t *testing.T) {
if err != nil {
t.Fatalf("Close: %v", err)
}
s := b.String()
if len(s) == 0 {
t.Fatal("String: unexpected empty result")
}
if s[0] == '\r' || s[0] == '\n' {
t.Fatal("String: unexpected newline")
}
}
r := NewReader(&b, w.Boundary())