mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
fix: setCookie
with maxAge
of 0
(#992)
This commit is contained in:
parent
3f3a1a74ba
commit
f3828fa852
@ -11,7 +11,7 @@ export interface Cookie {
|
||||
value: string;
|
||||
/** Expiration date of the cookie. */
|
||||
expires?: Date;
|
||||
/** Max-Age of the Cookie. Must be integer superior to 0. */
|
||||
/** Max-Age of the Cookie. Max-Age must be an integer superior or equal to 0. */
|
||||
maxAge?: number;
|
||||
/** Specifies those hosts to which the cookie will be sent. */
|
||||
domain?: string;
|
||||
@ -57,7 +57,10 @@ function toString(cookie: Cookie): string {
|
||||
out.push("HttpOnly");
|
||||
}
|
||||
if (typeof cookie.maxAge === "number" && Number.isInteger(cookie.maxAge)) {
|
||||
assert(cookie.maxAge > 0, "Max-Age must be an integer superior to 0");
|
||||
assert(
|
||||
cookie.maxAge >= 0,
|
||||
"Max-Age must be an integer superior or equal to 0",
|
||||
);
|
||||
out.push(`Max-Age=${cookie.maxAge}`);
|
||||
}
|
||||
if (cookie.domain) {
|
||||
|
@ -177,6 +177,19 @@ Deno.test({
|
||||
"Space=Cat; Secure; HttpOnly; Max-Age=2",
|
||||
);
|
||||
|
||||
res.headers = new Headers();
|
||||
setCookie(res, {
|
||||
name: "Space",
|
||||
value: "Cat",
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
maxAge: 0,
|
||||
});
|
||||
assertEquals(
|
||||
res.headers.get("Set-Cookie"),
|
||||
"Space=Cat; Secure; HttpOnly; Max-Age=0",
|
||||
);
|
||||
|
||||
let error = false;
|
||||
res.headers = new Headers();
|
||||
try {
|
||||
@ -185,7 +198,7 @@ Deno.test({
|
||||
value: "Cat",
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
maxAge: 0,
|
||||
maxAge: -1,
|
||||
});
|
||||
} catch {
|
||||
error = true;
|
||||
|
Loading…
Reference in New Issue
Block a user