From a6ad7ea767bf16a9b2b254215b7fb9734a0d120c Mon Sep 17 00:00:00 2001 From: tjarbo <16938041+tjarbo@users.noreply.github.com> Date: Tue, 8 Mar 2022 17:42:20 +0000 Subject: [PATCH] res.clearCookie now ignores maxAge. fixes #4851 --- lib/response.js | 1 + test/res.clearCookie.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/response.js b/lib/response.js index ccf8d91b2c..ea4aec77ef 100644 --- a/lib/response.js +++ b/lib/response.js @@ -805,6 +805,7 @@ res.get = function(field){ res.clearCookie = function clearCookie(name, options) { var opts = merge({ expires: new Date(1), path: '/' }, options); + delete opts.maxAge; return this.cookie(name, '', opts); }; diff --git a/test/res.clearCookie.js b/test/res.clearCookie.js index fc0cfb99a3..7eb967a892 100644 --- a/test/res.clearCookie.js +++ b/test/res.clearCookie.js @@ -32,5 +32,18 @@ describe('res', function(){ .expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT') .expect(200, done) }) + + it('should ignore maxAge', function(done){ + var app = express(); + + app.use(function(req, res){ + res.clearCookie('sid', { path: '/admin', maxAge: 900 }).end(); + }); + + request(app) + .get('/') + .expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT') + .expect(200, done) + }) }) })