Skip to content

Commit

Permalink
Fix regression for empty string path in app.use
Browse files Browse the repository at this point in the history
fixes #2361
fixes #2362
  • Loading branch information
dougwilson committed Sep 18, 2014
1 parent 947fb8b commit 3c1a964
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
unreleased
==========

* Fix regression for empty string `path` in `app.use`

4.9.1 / 2014-09-16
==================

Expand Down
3 changes: 2 additions & 1 deletion lib/application.js
Expand Up @@ -165,7 +165,8 @@ app.use = function use(fn) {
arg = arg[0];
}

if (typeof arg !== 'function' && (arg == null || arg.length !== 0)) {
// first arg is the path
if (typeof arg !== 'function') {
offset = 1;
path = fn;
}
Expand Down
12 changes: 12 additions & 0 deletions test/app.use.js
Expand Up @@ -503,5 +503,17 @@ describe('app', function(){
.get('/get/zoo')
.expect(404, cb);
})

it('should support empty string path', function (done) {
var app = express();

app.use('', function (req, res) {
res.send('saw ' + req.method + ' ' + req.url + ' through ' + req.originalUrl);
});

request(app)
.get('/')
.expect(200, 'saw GET / through /', done);
})
})
})

0 comments on commit 3c1a964

Please sign in to comment.