Skip to content

Commit

Permalink
GH-59 Routes with just / aren't working
Browse files Browse the repository at this point in the history
  • Loading branch information
mcavage committed Jan 28, 2012
1 parent ea4b73f commit 11ea3e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ function Route(options) {
self.pattern += fragment;
}
});
if (self.pattern === '^')
self.pattern += '\\/';
self.pattern += '$';
});

Expand Down Expand Up @@ -264,6 +266,7 @@ Route.prototype.matchesUrl = function matchesUrl(req) {
throw new TypeError('request (Object) required');

var re = new RegExp(this.pattern);
console.log(this.pattern + ' -> ' + req.path)
var result = re.exec(req.path);
if (!result)
return false;
Expand Down
38 changes: 38 additions & 0 deletions tst/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,44 @@ test('GH-56 streaming with filed (download)', function(t) {

});


test('GH-59 Query params with / result in a 404', function(t) {
var server = new Server({ dtrace: DTRACE, log4js: log4js });

server.get('/', function tester(req, res, next) {
res.send('hello');
return next();
});

server.listen(PORT, function() {
var opts = {
hostname: 'localhost',
port: PORT,
path: '/?foo=bar/foo',
method: 'GET',
agent: false,
headers: {
accept: 'text/plain'
}
};
http.request(opts, function(res) {
t.equal(res.statusCode, 200);
var body = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
t.equal(body, 'hello');
server.close(function() {
t.end();
});
});
}).end();
});

});

/*
* Disabled, as Heroku (travis) doesn't allow us to write to /tmp
*
Expand Down

0 comments on commit 11ea3e3

Please sign in to comment.