Skip to content
Myr

Ignore `expires` and `maxAge` in `res.clearCookie()` (#5792)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* add test for removing user provided expires * rework impl and tests to ignore maxAge, do not set it this is to take into account the built-in relative expires when passing a maxAge to res.cookie I realized that using maxAge to invalidate cookies inherrently hit this relativee expires behavior, and the goal of this PR is not to rework that relative expires behavior w/ maxAge, but to prevent users from overwriting these values by accident when clearing cookies * update history.md * explicitly delete maxAge instead of setting as undefined * drop the spread, use object.assign * wording, review comment on history.md Co-authored-by: Chris de Almeida <ctcpip@users.noreply.github.com> * ♻️ use spread, update supported ecmascript version ---------

authored by Jon Church · committed by GitHub · parent 160b91c · Browse files · 4 files+33 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Chris de Almeida <ctcpip@users.noreply.github.com>

Diff stats

4 files+33 added−2 removed

  • tests:+26 added−0 removed
  • other:+7 added−2 removed

4 files+33 added−2 removed

modified:lib/response.js+4 added-1 removed
705 unmodified lines
706 * @public707 */708709res.clearCookie = function clearCookie(name, options) {710 var opts = merge({ expires: new Date(1), path: '/' }, options);710 // Force cookie expiration by setting expires to the past711 const opts = { path: '/', ...options, expires: new Date(1)};712 // ensure maxAge is not passed713 delete opts.maxAge714715 return this.cookie(name, '', opts);716};717
337 unmodified lines
modified:test/res.clearCookie.js+26 added
modified:.eslintrc.yml+1 added-1 removed
modified:History.md+2 added
2 unmodified lines
3* breaking:4 * `res.status()` accepts only integers, and input must be greater than 99 and less than 10005 * will throw a `RangeError: Invalid status code: ${code}. Status code must be greater than 99 and less than 1000.` for inputs outside this range6 * will throw a `TypeError: Invalid status code: ${code}. Status code must be an integer.` for non integer inputs7* change:8 - `res.clearCookie` will ignore user provided `maxAge` and `expires` options9105.0.0-beta.3 / 2024-03-2511=========================12
3781 unmodified lines