mirror of https://github.com/golang/go.git
net/http: remove unnecessary string replace operation in Cookie.String
Fixes #29135
Change-Id: I4c10b0395047775e8488b8b0f00f74a7fa01b86c
GitHub-Last-Rev: 1209770405
GitHub-Pull-Request: golang/go#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>
This commit is contained in:
parent
6b7114b9e5
commit
09b2b6e9dd
|
|
@ -173,7 +173,7 @@ func (c *Cookie) String() string {
|
||||||
const extraCookieLength = 110
|
const extraCookieLength = 110
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.Grow(len(c.Name) + len(c.Value) + len(c.Domain) + len(c.Path) + extraCookieLength)
|
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.WriteRune('=')
|
||||||
b.WriteString(sanitizeCookieValue(c.Value))
|
b.WriteString(sanitizeCookieValue(c.Value))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,22 @@ var writeSetCookiesTests = []struct {
|
||||||
&Cookie{Name: "\t"},
|
&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) {
|
func TestWriteSetCookies(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue