Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

res.clearCookie() now ignores maxAge #4852

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tjarbo
Copy link

@tjarbo tjarbo commented Mar 8, 2022

This pr fixes #4851.

I have ...

  • added a new test that covers my changes
  • run linter

@import-brain import-brain added the pr label Mar 8, 2022
@dougwilson dougwilson added this to the 4.18 milestone Mar 13, 2022
@dougwilson dougwilson added 5.x and removed bug 4.x labels Mar 24, 2022
@dougwilson dougwilson removed this from the 4.18 milestone Mar 24, 2022
@Segmentational
Copy link

Testing the changes, in the unit-test:

  // ... blah blah blah
  [Symbol(kOutHeaders)]: [Object: null prototype] {
    'x-powered-by': [ 'X-Powered-By', 'Express' ],
    'set-cookie': [
      'Set-Cookie',
      'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT'
    ]
  }
}

confirms the maxAge attribute is indeed removed. Output following the request.end() call yields

// ... blah blah blah
 _maxListeners: undefined,
  _enableHttp2: false,
  _agent: false,
  _formData: null,
  method: 'GET',
  url: 'http://127.0.0.1:46159/',
  _header: {},
  header: {},
  writable: true,
  _redirects: 0,
  _maxRedirects: 0,
  cookies: '',
// ... blah blah blah

Great, cookies are not set in the raw http response!

Due to my little experience in our test suite, another PR would be useful. But to my understanding things are looking good.

var app = express();

app.use(function(req, res){
res.clearCookie('sid', { path: '/admin', maxAge: 900 }).end();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  // ... blah blah blah
  [Symbol(kOutHeaders)]: [Object: null prototype] {
    'x-powered-by': [ 'X-Powered-By', 'Express' ],
    'set-cookie': [
      'Set-Cookie',
      'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT'
    ]
  }
}

.get('/')
.expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
.expect(200, done)
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Takes the shape:

// ... blah blah blah
 _maxListeners: undefined,
  _enableHttp2: false,
  _agent: false,
  _formData: null,
  method: 'GET',
  url: 'http://127.0.0.1:46159/',
  _header: {},
  header: {},
  writable: true,
  _redirects: 0,
  _maxRedirects: 0,
  cookies: '',
// ... blah blah blah

Copy link

@Segmentational Segmentational left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good -- I was able to verify the expected raw http outputs

Copy link

@kaj kaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

res.clearCookie() does not ignore maxAge
5 participants