From 129233ac1b16b461f491c5557355b52eb89b193e Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Fri, 15 Dec 2023 20:51:54 -0300 Subject: [PATCH] fix: skip cookie if name is empty Signed-off-by: Felipe Zipitria --- internal/cookies/cookies.go | 4 ++++ internal/cookies/cookies_test.go | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/cookies/cookies.go b/internal/cookies/cookies.go index 8719a0f08..165e3eeca 100644 --- a/internal/cookies/cookies.go +++ b/internal/cookies/cookies.go @@ -26,6 +26,10 @@ func ParseCookies(rawCookies string) map[string][]string { } name, val, _ := strings.Cut(part, "=") name = textproto.TrimString(name) + // if name is empty (eg: "Cookie: =foo;") skip it + if name == "" { + continue + } cookies[name] = append(cookies[name], val) } return cookies diff --git a/internal/cookies/cookies_test.go b/internal/cookies/cookies_test.go index 6b314f198..99dd7e214 100644 --- a/internal/cookies/cookies_test.go +++ b/internal/cookies/cookies_test.go @@ -62,8 +62,13 @@ func TestParseCookies(t *testing.T) { }, { name: "EmptyCookie", - args: args{rawCookies: "test1=value1;;test2=value2"}, - want: map[string][]string{"test1": {"value1"}, "test2": {"value2"}}, + args: args{rawCookies: ";;foo=bar"}, + want: map[string][]string{"foo": {"bar"}}, + }, + { + name: "EmptyName", + args: args{rawCookies: "=bar;"}, + want: map[string][]string{}, }, { name: "MultipleEqualsInValues",