Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: case sensitive header options #194

Merged
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
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
Loading