Skip to content

Commit

Permalink
Merge pull request hapijs#925 from wpreul/master
Browse files Browse the repository at this point in the history
Fixing edge case where bad path can cause issues with url.parse
  • Loading branch information
Eran Hammer committed Jun 13, 2013
2 parents d9006c7 + 7c67eee commit 5b34fca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/unit/request.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 5b34fca

Please sign in to comment.