Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export function stringifySetCookie(
throw new TypeError(`argument name is invalid: ${cookie.name}`);
}

const value = cookie.value ? enc(cookie.value) : "";
const value = cookie.value == null ? "" : enc(cookie.value);

if (!cookieValueRegExp.test(value)) {
throw new TypeError(`argument val is invalid: ${cookie.value}`);
Expand Down
9 changes: 9 additions & 0 deletions src/stringify-set-cookie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ describe("cookie.stringifySetCookie", () => {
).toEqual("foo=YmFy");
});

it("should apply the encoder to an empty value", function () {
expect(
stringifySetCookie(
{ name: "foo", value: "" },
{ encode: (v) => "[" + v + "]" },
),
).toEqual("foo=[]");
});

it.each(["foo=bar", 'foo"bar', "foo,bar", "foo\\bar", "foo$bar"])(
"should serialize value: %s",
(value) => {
Expand Down
Loading