Skip to content

Commit

Permalink
when cookie path === null dont default it
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 4, 2011
1 parent 6815feb commit ee4471b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/response.js
Expand Up @@ -322,7 +322,7 @@ res.clearCookie = function(name, options){
res.cookie = function(name, val, options){
options = options || {};
if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);
options.path = options.path || this.app.set('home');
if (undefined === options.path) options.path = this.app.set('home');
var cookie = utils.serializeCookie(name, val, options);
this.header('Set-Cookie', cookie);
};
Expand Down
19 changes: 19 additions & 0 deletions test/response.test.js
Expand Up @@ -650,6 +650,25 @@ module.exports = {
});
},

'test #cookie() null path': function(){
var app = express.createServer();

app.set('/home', '/foo');

app.get('/', function(req, res){
res.cookie('rememberme', 'yes', { path: null, expires: new Date(1), httpOnly: true });
res.cookie('something', 'else', { path: null });
res.redirect('/');
});

assert.response(app,
{ url: '/', headers: { Host: 'foo.com' }},
function(res){
res.headers['set-cookie']
.should.eql(['rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else']);
});
},

'test #clearCookie() default path': function(){
var app = express.createServer();

Expand Down

0 comments on commit ee4471b

Please sign in to comment.