Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
Paths should be normalized.
Browse files Browse the repository at this point in the history
  • Loading branch information
pluma committed Mar 8, 2014
1 parent 452b21d commit ce61218
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions index.js
@@ -1,7 +1,8 @@
/*! routes-http 0.4.0 Original author Alan Plum <me@pluma.io>. Released into the Public Domain under the UNLICENSE. @preserve */
/*! routes-http 0.4.1 Original author Alan Plum <me@pluma.io>. Released into the Public Domain under the UNLICENSE. @preserve */
var httperr = require('httperr');
var router = require('routes');
var parseUrl = require('url').parse;
var normalize = require('path').normalize;

module.exports = function() {
var routes = router();
Expand Down Expand Up @@ -48,7 +49,7 @@ module.exports = function() {
} else {
pathname = parseUrl(req.url).pathname;
}
var route = routes.match(pathname);
var route = routes.match(normalize(pathname));
if (!route) {
throw httperr.notFound();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "routes-http",
"version": "0.4.0",
"version": "0.4.1",
"author": "Alan Plum <me@pluma.io>",
"description": "Simple but powerful HTTP request router",
"licenses": {
Expand Down
7 changes: 7 additions & 0 deletions spec/router.spec.js
Expand Up @@ -93,6 +93,13 @@ describe('route with plain function', function() {
});
routes(req0, res0);
});
it('normalizes the path', function(done) {
var routes = router();
routes.addRoute('/foo/bar', function() {
done();
});
routes({url: 'http://localhost//foo/bar'});
});
it('passes along the failure callback', function(done) {
var routes = router(),
callback = function() {};
Expand Down

0 comments on commit ce61218

Please sign in to comment.