From 321932f343b8dec6a8803f331a6fd2fc3a9a1d25 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 9 Oct 2024 06:12:32 -0400 Subject: [PATCH] fastifyCookieClearCookie sets maxAge to zero (#304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fastifyCookieClearCookie sets maxAge to zero * apply suggestions * update passed type --------- Co-authored-by: Gürgün Dayıoğlu --- plugin.js | 6 +++--- test/cookie.test.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin.js b/plugin.js index 8aec1ca..7fc28b2 100644 --- a/plugin.js +++ b/plugin.js @@ -40,9 +40,9 @@ function fastifyCookieSetCookie (reply, name, value, options) { function fastifyCookieClearCookie (reply, name, options) { const opts = Object.assign({ path: '/' }, options, { - expires: new Date(1), - signed: undefined, - maxAge: undefined + expires: new Date(0), + maxAge: 0, + signed: false }) return fastifyCookieSetCookie(reply, name, '', opts) diff --git a/test/cookie.test.js b/test/cookie.test.js index 7f277f1..77e1c22 100644 --- a/test/cookie.test.js +++ b/test/cookie.test.js @@ -224,7 +224,7 @@ test('share options for setCookie and clearCookie', (t) => { t.equal(cookies.length, 1) t.equal(cookies[0].name, 'foo') t.equal(cookies[0].value, '') - t.equal(cookies[0].maxAge, undefined) + t.equal(cookies[0].maxAge, 0) t.ok(new Date(cookies[0].expires) < new Date()) }) @@ -1054,7 +1054,7 @@ test('clearCookie should include parseOptions', (t) => { t.equal(cookies.length, 1) t.equal(cookies[0].name, 'foo') t.equal(cookies[0].value, '') - t.equal(cookies[0].maxAge, undefined) + t.equal(cookies[0].maxAge, 0) t.equal(cookies[0].path, '/test') t.equal(cookies[0].domain, 'example.com')