Skip to content

Commit

Permalink
fix: skip cookie if name is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Zipitria <[email protected]>
  • Loading branch information
fzipi committed Dec 15, 2023
1 parent b14e973 commit 129233a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/cookies/cookies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions internal/cookies/cookies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 129233a

Please sign in to comment.