diff --git a/HISTORY.md b/HISTORY.md index b2bdf23a..79f07def 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ unreleased ========== + * Fix `TypeError` when `req.url` is an empty string * deps: depd@~1.1.1 - Remove unnecessary `Buffer` loading diff --git a/index.js b/index.js index 8db4eca3..175fb234 100644 --- a/index.js +++ b/index.js @@ -191,7 +191,7 @@ function session(options) { } // pathname mismatch - var originalPath = parseUrl.original(req).pathname; + var originalPath = parseUrl.original(req).pathname || '/' if (originalPath.indexOf(cookieOptions.path || '/') !== 0) return next(); // ensure a secret is available or bail diff --git a/test/session.js b/test/session.js index 4a7a2263..241eb5f6 100644 --- a/test/session.js +++ b/test/session.js @@ -164,6 +164,17 @@ describe('session()', function(){ .expect(200, 'session created', cb) }) + it('should handle empty req.url', function (done) { + function setup (req) { + req.url = '' + } + + request(createServer(setup)) + .get('/') + .expect(shouldSetCookie('connect.sid')) + .expect(200, done) + }) + it('should handle multiple res.end calls', function(done){ var server = createServer(null, function (req, res) { res.setHeader('Content-Type', 'text/plain')