]> Cypherpunks repositories - gostls13.git/commitdiff
mime/multipart: allow boundary len <= 70
authorPatrick Pelletier <pp.pelletier@gmail.com>
Thu, 26 Jan 2017 06:09:26 +0000 (22:09 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 1 Feb 2017 21:06:49 +0000 (21:06 +0000)
As per RFC 2046, the boundary for multipart MIME is allowed up to 70
characters. The old SetBoundary implementation only allowed up to 69 so
this bumps it to the correct value of 70.

The relevant RFC is at https://www.ietf.org/rfc/rfc2046.txt and section
5.1.1 defines the boundary specification.

Fixes #18793

Change-Id: I91d2ed4549c3d27d6049cb473bac680a750fb520
Reviewed-on: https://go-review.googlesource.com/35830
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/mime/multipart/writer.go
src/mime/multipart/writer_test.go

index f82756d55185e2eb4a0cda34dafe98ed192bd748..44e2f1bce355f0ad35624fdba22d066e23674bbe 100644 (file)
@@ -41,13 +41,13 @@ func (w *Writer) Boundary() string {
 //
 // SetBoundary must be called before any parts are created, may only
 // contain certain ASCII characters, and must be non-empty and
-// at most 69 bytes long.
+// at most 70 bytes long.
 func (w *Writer) SetBoundary(boundary string) error {
        if w.lastpart != nil {
                return errors.New("mime: SetBoundary called after write")
        }
        // rfc2046#section-5.1.1
-       if len(boundary) < 1 || len(boundary) > 69 {
+       if len(boundary) < 1 || len(boundary) > 70 {
                return errors.New("mime: invalid boundary length")
        }
        for _, b := range boundary {
index 9670c660a4a0b72d7c5f544b9ce4783efcf82d54..23e650f5e44736075b3b5b29194ae34cc16df5ee 100644 (file)
@@ -90,8 +90,8 @@ func TestWriterSetBoundary(t *testing.T) {
                {"", false},
                {"ungültig", false},
                {"!", false},
-               {strings.Repeat("x", 69), true},
-               {strings.Repeat("x", 70), false},
+               {strings.Repeat("x", 70), true},
+               {strings.Repeat("x", 71), false},
                {"bad!ascii!", false},
                {"my-separator", true},
        }