diff --git a/src/index.ts b/src/index.ts index 5a8e0e8..af222fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -308,7 +308,11 @@ export function serialize( } if (options.priority) { - switch (options.priority) { + const priority = + typeof options.priority === "string" + ? options.priority.toLowerCase() + : options.sameSite; + switch (priority) { case "low": str += "; Priority=Low"; break; @@ -324,7 +328,11 @@ export function serialize( } if (options.sameSite) { - switch (options.sameSite) { + const sameSite = + typeof options.sameSite === "string" + ? options.sameSite.toLowerCase() + : options.sameSite; + switch (sameSite) { case true: case "strict": str += "; SameSite=Strict"; diff --git a/src/serialize.spec.ts b/src/serialize.spec.ts index e9a6ba8..7091027 100644 --- a/src/serialize.spec.ts +++ b/src/serialize.spec.ts @@ -282,6 +282,13 @@ describe("cookie.serialize(name, value, options)", function () { "foo=bar; Priority=High", ); }); + + it("should set priority case insensitive", function () { + /** @ts-expect-error */ + expect(cookie.serialize("foo", "bar", { priority: "High" })).toEqual( + "foo=bar; Priority=High", + ); + }); }); describe('with "sameSite" option', function () { @@ -320,6 +327,13 @@ describe("cookie.serialize(name, value, options)", function () { "foo=bar", ); }); + + it("should set sameSite case insensitive", function () { + /** @ts-expect-error */ + expect(cookie.serialize("foo", "bar", { sameSite: "Lax" })).toEqual( + "foo=bar; SameSite=Lax", + ); + }); }); describe('with "secure" option', function () {