diff --git a/lib/request.js b/lib/request.js index c79c6ab12..2ae505b28 100755 --- a/lib/request.js +++ b/lib/request.js @@ -29,7 +29,7 @@ exports = module.exports = internals.Request = function (server, req, res, optio // Public members this.server = server; - + this.url = null; this.query = null; this.path = null; @@ -40,7 +40,7 @@ exports = module.exports = internals.Request = function (server, req, res, optio this.setUrl(req.url); // Sets: this.url, this.path, this.query this.setMethod(req.method); // Sets: this.method - + this.id = now + '-' + process.pid + '-' + Math.floor(Math.random() * 0x10000); this.app = {}; // Place for application-specific state without conflicts with hapi, should not be used by plugins @@ -258,7 +258,7 @@ internals.Request.prototype._execute = function () { return; } - if (self.path[0] !== '/') { + if (!self.path || self.path[0] !== '/') { self._reply(Boom.badRequest('Invalid path')); return; } @@ -269,7 +269,7 @@ internals.Request.prototype._execute = function () { self.route = self._route.settings; // Setup timer - + var serverTimeout = self.server.settings.timeout.server; if (serverTimeout) { serverTimeout -= (Date.now() - self._timestamp); // Calculate the timeout from when the request was constructed diff --git a/test/unit/request.js b/test/unit/request.js index ad3b410c2..027e21188 100755 --- a/test/unit/request.js +++ b/test/unit/request.js @@ -1,6 +1,7 @@ // Load modules var Lab = require('lab'); +var Hoek = require('hoek'); var Shot = require('shot'); var Hapi = require('../..'); var Request = require('../../lib/request'); @@ -124,6 +125,24 @@ describe('Request', function () { expect(request.query.param1).to.equal('something'); done(); }); + + it('doesn\'t throw when path is missing from request and execute is called', function (done) { + + var brokeServer = new Hapi.Server(); + var req = Hoek.clone(_req); + req.once = function () { }; + req.removeAllListeners = function () { }; + req.destroy = function () { }; + req.url = 'ssh://something'; + + var request = new Request(brokeServer, req, _res, {}); + request._execute(); + + setTimeout(function () { + + done(); + }, 10); + }); }); describe('#log', function () {