mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 00:19:48 +01:00
Fix behavior of null/undefined as "maxAge" in res.cookie
fixes #3935 closes #3936
This commit is contained in:
parent
1cc8169938
commit
5855339455
|
|
@ -4,6 +4,7 @@ unreleased
|
|||
* Add "root" option to `res.download`
|
||||
* Allow `options` without `filename` in `res.download`
|
||||
* Deprecate string and non-integer arguments to `res.status`
|
||||
* Fix behavior of `null`/`undefined` as `maxAge` in `res.cookie`
|
||||
* Ignore `Object.prototype` values in settings through `app.set`/`app.get`
|
||||
* Invoke `default` with same arguments as types in `res.format`
|
||||
* Support proper 205 responses using `res.send`
|
||||
|
|
|
|||
|
|
@ -868,9 +868,13 @@ res.cookie = function (name, value, options) {
|
|||
val = 's:' + sign(val, secret);
|
||||
}
|
||||
|
||||
if ('maxAge' in opts) {
|
||||
opts.expires = new Date(Date.now() + opts.maxAge);
|
||||
opts.maxAge /= 1000;
|
||||
if (opts.maxAge != null) {
|
||||
var maxAge = opts.maxAge - 0
|
||||
|
||||
if (!isNaN(maxAge)) {
|
||||
opts.expires = new Date(Date.now() + maxAge)
|
||||
opts.maxAge = Math.floor(maxAge / 1000)
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.path == null) {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,36 @@ describe('res', function(){
|
|||
.expect(200, optionsCopy, done)
|
||||
})
|
||||
|
||||
it('should not throw on null', function (done) {
|
||||
var app = express()
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.cookie('name', 'tobi', { maxAge: null })
|
||||
res.end()
|
||||
})
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Set-Cookie', 'name=tobi; Path=/')
|
||||
.end(done)
|
||||
})
|
||||
|
||||
it('should not throw on undefined', function (done) {
|
||||
var app = express()
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.cookie('name', 'tobi', { maxAge: undefined })
|
||||
res.end()
|
||||
})
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Set-Cookie', 'name=tobi; Path=/')
|
||||
.end(done)
|
||||
})
|
||||
|
||||
it('should throw an error with invalid maxAge', function (done) {
|
||||
var app = express()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user