Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with case-insensitive route conflic #299

Merged
merged 1 commit into from
Dec 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.server = {
// Router

router: {
isTrailingSlashSensitive: false, // Tread trailing '/' in path as different resources
isTrailingSlashSensitive: false, // Treat trailing '/' in path as different resources
isCaseSensitive: true, // Case-seinsitive paths
normalizeRequestPath: false // Normalize incoming request path (Uppercase % encoding and decode non-reserved encoded characters)
},
Expand Down
3 changes: 2 additions & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ internals.Route.prototype._generateRegex = function () {

if (this.server.settings.router.isCaseSensitive) {
this.regexp = new RegExp('^' + pathRX + '$');
this.fingerprint = fingerprint;
}
else {
this.regexp = new RegExp('^' + pathRX + '$', 'i');
this.fingerprint = fingerprint.toLowerCase();
}

this.params = Object.keys(params);
this.fingerprint = fingerprint;
};


Expand Down
24 changes: 24 additions & 0 deletions test/unit/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,30 @@ describe('Server', function () {
expect(fn).to.throw(Error);
done();
});

it('doesn\'t throw an error when routes differ in case and case is sensitive', function (done) {

var fn = function () {

var server = new Hapi.Server({ router: { isCaseSensitive: true } });
server.addRoute({ path: '/test/{p}/End', method: 'put', handler: function () { } });
server.addRoute({ path: '/test/{p}/end', method: 'put', handler: function () { } });
};
expect(fn).to.not.throw(Error);
done();
});

it('throws an error when routes differ in case and case is insensitive', function (done) {

var fn = function () {

var server = new Hapi.Server({ router: { isCaseSensitive: false } });
server.addRoute({ path: '/test/{p}/End', method: 'put', handler: function () { } });
server.addRoute({ path: '/test/{p}/end', method: 'put', handler: function () { } });
};
expect(fn).to.throw(Error);
done();
});
});

describe('#addRoutes', function () {
Expand Down