Skip to content

Commit 9d08299

Browse files
committed
net/http: fix cookie value of "" being interpreted as empty string.
In issue #46443, we have established that double-quotes in cookie values should be kept as part of the value, rather than being discarded. However, we have missed the edge case of "" until now. This CL fixes said edge case. Fixes #75244 Change-Id: I627ad2376931514aa5dcc8961ad804e42b7d9434 Reviewed-on: https://go-review.googlesource.com/c/go/+/700755 Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Nicholas Husin <husin@google.com> Reviewed-by: Damien Neil <dneil@google.com>
1 parent ddce052 commit 9d08299

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

src/net/http/cookie.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,6 @@ func sanitizeCookieName(n string) string {
459459
// See https://golang.org/issue/7243 for the discussion.
460460
func sanitizeCookieValue(v string, quoted bool) string {
461461
v = sanitizeOrWarn("Cookie.Value", validCookieValueByte, v)
462-
if len(v) == 0 {
463-
return v
464-
}
465462
if strings.ContainsAny(v, " ,") || quoted {
466463
return `"` + v + `"`
467464
}

src/net/http/cookie_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ func TestCookieSanitizeValue(t *testing.T) {
530530
{"a,z", false, `"a,z"`},
531531
{",z", false, `",z"`},
532532
{"a,", false, `"a,"`},
533+
{"", true, `""`},
533534
}
534535
for _, tt := range tests {
535536
if got := sanitizeCookieValue(tt.in, tt.quoted); got != tt.want {

0 commit comments

Comments
 (0)