Skip to content

Commit 68290ee

Browse files
committed
Fix handling of invalid empty URLs
fixes expressjs#2399
1 parent 6614352 commit 68290ee

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ unreleased
44
* Add support for `app.set('views', array)`
55
- Views are looked up in sequence in array of directories
66
* Fix `res.send(status)` to mention `res.sendStatus(status)`
7+
* Fix handling of invalid empty URLs
78
* Use `content-disposition` module for `res.attachment`/`res.download`
89
- Sends standards-compliant `Content-Disposition` header
910
- Full Unicode support

lib/router/layer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ Layer.prototype.handle_request = function handle(req, res, next) {
9595
*/
9696

9797
Layer.prototype.match = function match(path) {
98+
if (path == null) {
99+
// no path, nothing matches
100+
this.params = undefined;
101+
this.path = undefined;
102+
return false;
103+
}
104+
98105
if (this.regexp.fast_slash) {
99106
// fast path non-ending match for / (everything matches)
100107
this.params = {};

test/Router.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ describe('Router', function(){
4343
router.handle({ url: '/test/route', method: 'GET' }, { end: done });
4444
});
4545

46+
it('should handle blank URL', function(done){
47+
var router = new Router();
48+
49+
router.use(function (req, res) {
50+
false.should.be.true;
51+
});
52+
53+
router.handle({ url: '', method: 'GET' }, {}, done);
54+
});
55+
4656
describe('.handle', function(){
4757
it('should dispatch', function(done){
4858
var router = new Router();

0 commit comments

Comments
 (0)