Permalink
Browse files

Merge pull request #84 from guybedford/master

Malformed URI fix
  • Loading branch information...
2 parents 0f20852 + 11e9782 commit f1dbda9e130a9e3c903b83200335ce9118907ff6 @phstc phstc committed Feb 4, 2013
Showing with 19 additions and 2 deletions.
  1. +10 −2 lib/node-static.js
  2. +9 −0 test/integration/node-static-test.js
View
@@ -171,12 +171,20 @@ exports.Server.prototype.serve = function (req, res, callback) {
var that = this,
promise = new(events.EventEmitter);
- var pathname = decodeURI(url.parse(req.url).pathname);
-
var finish = function (status, headers) {
that.finish(status, headers, req, res, promise, callback);
};
+ var pathname;
+ try {
+ pathname = decodeURI(url.parse(req.url).pathname);
+ }
+ catch(e) {
+ return process.nextTick(function() {
+ return finish(400, {});
+ });
+ }
+
process.nextTick(function () {
that.servePath(pathname, 200, {}, req, res, finish).on('success', function (result) {
promise.emit('success', result);
@@ -79,6 +79,15 @@ suite.addBatch({
}
}
}).addBatch({
+ 'requesting a malformed URI': {
+ topic: function(){
+ request.get(TEST_SERVER + '/a%AFc', this.callback);
+ },
+ 'should respond with 400': function(error, response, body){
+ assert.equal(response.statusCode, 400);
+ }
+ }
+}).addBatch({
'serving hello.txt': {
topic : function(){
request.get(TEST_SERVER + '/hello.txt', this.callback);

2 comments on commit f1dbda9

Contributor

dubiousdavid replied Apr 1, 2013

This commit never got published as 0.6.7?

Collaborator

phstc replied Apr 2, 2013

I just published the version 0.6.8. 😄

Please sign in to comment.