diff options
author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2011-06-23 10:11:33 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2011-06-23 10:11:33 -0700 |
commit | 73d741fd5b767f671dc3bb466ae28c51b0222f8c (patch) | |
tree | bac5c8415cdba1453b12351f141474098001d364 | |
parent | d847467041ab93c108b932c25f6ccaa37bfccc47 (diff) | |
download | go-73d741fd5b767f671dc3bb466ae28c51b0222f8c.tar.gz go-73d741fd5b767f671dc3bb466ae28c51b0222f8c.zip |
mime/multipart: remove newline at top of the multipart.
R=golang-dev, bradfitz, arctanofyourface
CC=golang-dev
https://golang.org/cl/4635063
-rw-r--r-- | src/pkg/mime/multipart/writer.go | 6 | ||||
-rw-r--r-- | src/pkg/mime/multipart/writer_test.go | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/pkg/mime/multipart/writer.go b/src/pkg/mime/multipart/writer.go index b436dd0124..97a8897b29 100644 --- a/src/pkg/mime/multipart/writer.go +++ b/src/pkg/mime/multipart/writer.go @@ -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 { diff --git a/src/pkg/mime/multipart/writer_test.go b/src/pkg/mime/multipart/writer_test.go index e6a04c3887..494e936c4c 100644 --- a/src/pkg/mime/multipart/writer_test.go +++ b/src/pkg/mime/multipart/writer_test.go @@ -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()) |