Skip to content

Commit

Permalink
Fix TypeError when req.url is an empty string
Browse files Browse the repository at this point in the history
fixes #495
  • Loading branch information
dougwilson committed Aug 3, 2017
1 parent 62c4d15 commit c226301
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==========

* Fix `TypeError` when `req.url` is an empty string
* deps: depd@~1.1.1
- Remove unnecessary `Buffer` loading

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit c226301

Please sign in to comment.