Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #16 from rndstr/fix/object-prototype-properties-ty…
…peerror

fix TypeError if path /constructor/foo is accessed
  • Loading branch information
hueniverse committed May 19, 2016
2 parents 0a307ad + c4792f9 commit 8043e25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/segment.js
Expand Up @@ -174,7 +174,8 @@ internals.Segment.prototype.lookup = function (path, segments, options) {
const remainder = (segments.length > 1 ? segments.slice(1) : null);

if (this._literals) {
match = this._literals[options.isCaseSensitive ? current : current.toLowerCase()];
const literal = options.isCaseSensitive ? current : current.toLowerCase();
match = this._literals.hasOwnProperty(literal) && this._literals[literal];
if (match) {
const record = internals.deeper(match, nextPath, remainder, [], options);
if (record) {
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Expand Up @@ -675,6 +675,15 @@ describe('Router', () => {
expect(router.route('get', '/a/%p').output.statusCode).to.equal(400);
done();
});

it('fails to match js object prototype properties for literals', (done) => {

const router = new Call.Router();
router.add({ method: 'get', path: '/a/{b}' }, '/');
expect(router.route('get', '/constructor/').output.statusCode).to.equal(404);
expect(router.route('get', '/hasOwnProperty/').output.statusCode).to.equal(404);
done();
});
});

describe('normalize()', () => {
Expand Down

0 comments on commit 8043e25

Please sign in to comment.