Skip to content

Commit 3bed080

Browse files
Allow case insensitive options (#194)
1 parent bc66a7e commit 3bed080

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Diff for: src/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,11 @@ export function serialize(
308308
}
309309

310310
if (options.priority) {
311-
switch (options.priority) {
311+
const priority =
312+
typeof options.priority === "string"
313+
? options.priority.toLowerCase()
314+
: options.sameSite;
315+
switch (priority) {
312316
case "low":
313317
str += "; Priority=Low";
314318
break;
@@ -324,7 +328,11 @@ export function serialize(
324328
}
325329

326330
if (options.sameSite) {
327-
switch (options.sameSite) {
331+
const sameSite =
332+
typeof options.sameSite === "string"
333+
? options.sameSite.toLowerCase()
334+
: options.sameSite;
335+
switch (sameSite) {
328336
case true:
329337
case "strict":
330338
str += "; SameSite=Strict";

Diff for: src/serialize.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ describe("cookie.serialize(name, value, options)", function () {
282282
"foo=bar; Priority=High",
283283
);
284284
});
285+
286+
it("should set priority case insensitive", function () {
287+
/** @ts-expect-error */
288+
expect(cookie.serialize("foo", "bar", { priority: "High" })).toEqual(
289+
"foo=bar; Priority=High",
290+
);
291+
});
285292
});
286293

287294
describe('with "sameSite" option', function () {
@@ -320,6 +327,13 @@ describe("cookie.serialize(name, value, options)", function () {
320327
"foo=bar",
321328
);
322329
});
330+
331+
it("should set sameSite case insensitive", function () {
332+
/** @ts-expect-error */
333+
expect(cookie.serialize("foo", "bar", { sameSite: "Lax" })).toEqual(
334+
"foo=bar; SameSite=Lax",
335+
);
336+
});
323337
});
324338

325339
describe('with "secure" option', function () {

0 commit comments

Comments
 (0)