Skip to content

Commit

Permalink
Allow case insensitive options (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenDittmann authored Oct 11, 2024
1 parent bc66a7e commit 3bed080
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down
14 changes: 14 additions & 0 deletions src/serialize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 3bed080

Please sign in to comment.