Commit 1ef3a77e authored by Patrick Pelletier's avatar Patrick Pelletier Committed by Brad Fitzpatrick

mime/multipart: allow boundary len <= 70

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/35830Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent ec4062f8
......@@ -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 {
......
......@@ -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},
}
......
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