Skip to content

Commit

Permalink
net/http: remove unnecessary string replace operation in Cookie.String
Browse files Browse the repository at this point in the history
Fixes #29135

Change-Id: I4c10b0395047775e8488b8b0f00f74a7fa01b86c
GitHub-Last-Rev: 1209770
GitHub-Pull-Request: #29728
Reviewed-on: https://go-review.googlesource.com/c/go/+/157777
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
bronze1man authored and bradfitz committed Apr 15, 2019
1 parent 6b7114b commit 09b2b6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/net/http/cookie.go
Expand Up @@ -173,7 +173,7 @@ func (c *Cookie) String() string {
const extraCookieLength = 110
var b strings.Builder
b.Grow(len(c.Name) + len(c.Value) + len(c.Domain) + len(c.Path) + extraCookieLength)
b.WriteString(sanitizeCookieName(c.Name))
b.WriteString(c.Name)
b.WriteRune('=')
b.WriteString(sanitizeCookieValue(c.Value))

Expand Down
16 changes: 16 additions & 0 deletions src/net/http/cookie_test.go
Expand Up @@ -127,6 +127,22 @@ var writeSetCookiesTests = []struct {
&Cookie{Name: "\t"},
``,
},
{
&Cookie{Name: "\r"},
``,
},
{
&Cookie{Name: "a\nb", Value: "v"},
``,
},
{
&Cookie{Name: "a\nb", Value: "v"},
``,
},
{
&Cookie{Name: "a\rb", Value: "v"},
``,
},
}

func TestWriteSetCookies(t *testing.T) {
Expand Down

0 comments on commit 09b2b6e

Please sign in to comment.