From 368f50fcb4c7537b90249c3c497e61dc81038f6e Mon Sep 17 00:00:00 2001 From: darmiel <71837281+darmiel@users.noreply.github.com> Date: Wed, 4 May 2022 14:38:10 +0200 Subject: [PATCH] net/http: check if strings.Cut was successful before trimming the cookie name --- src/net/http/cookie.go | 2 +- src/net/http/cookie_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/net/http/cookie.go b/src/net/http/cookie.go index 1810790ac3..8add1ffdc7 100644 --- a/src/net/http/cookie.go +++ b/src/net/http/cookie.go @@ -70,10 +70,10 @@ func readSetCookies(h Header) []*Cookie { } parts[0] = textproto.TrimString(parts[0]) name, value, ok := strings.Cut(parts[0], "=") - name = textproto.TrimString(name) if !ok { continue } + name = textproto.TrimString(name) if !isCookieNameValid(name) { continue } diff --git a/src/net/http/cookie_test.go b/src/net/http/cookie_test.go index 3c5c50b632..0db138e4f1 100644 --- a/src/net/http/cookie_test.go +++ b/src/net/http/cookie_test.go @@ -352,6 +352,8 @@ var readSetCookiesTests = []struct { Header{"Set-Cookie": {`special-8=","`}}, []*Cookie{{Name: "special-8", Value: ",", Raw: `special-8=","`}}, }, + // Make sure we can properly read back the Set-Cookie headers + // for names containing spaces: { Header{"Set-Cookie": {`special-9 =","`}}, []*Cookie{{Name: "special-9", Value: ",", Raw: `special-9 =","`}},