Skip to content

Commit c226301

Browse files
committed
Fix TypeError when req.url is an empty string
fixes expressjs#495
1 parent 62c4d15 commit c226301

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

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

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function session(options) {
191191
}
192192

193193
// pathname mismatch
194-
var originalPath = parseUrl.original(req).pathname;
194+
var originalPath = parseUrl.original(req).pathname || '/'
195195
if (originalPath.indexOf(cookieOptions.path || '/') !== 0) return next();
196196

197197
// ensure a secret is available or bail

test/session.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ describe('session()', function(){
164164
.expect(200, 'session created', cb)
165165
})
166166

167+
it('should handle empty req.url', function (done) {
168+
function setup (req) {
169+
req.url = ''
170+
}
171+
172+
request(createServer(setup))
173+
.get('/')
174+
.expect(shouldSetCookie('connect.sid'))
175+
.expect(200, done)
176+
})
177+
167178
it('should handle multiple res.end calls', function(done){
168179
var server = createServer(null, function (req, res) {
169180
res.setHeader('Content-Type', 'text/plain')

0 commit comments

Comments
 (0)