Skip to content

Commit

Permalink
fix(urlMatcherFactory): include the slash in squashed params
Browse files Browse the repository at this point in the history
Squashed params were ignoring a missing slash before the param so things
like /users123 would match /url/:id

Fixes #2064
  • Loading branch information
eddiemonge committed Jun 26, 2015
1 parent 4b978ac commit b5130bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ function UrlMatcher(pattern, config, parentMatcher) {
if (!pattern) return result;
switch(squash) {
case false: surroundPattern = ['(', ')' + (optional ? "?" : "")]; break;
case true: surroundPattern = ['?(', ')?']; break;
case true:
result = result.replace(/\/$/, '');
surroundPattern = ['(?:\/(', ')|\/)?'];
break;
default: surroundPattern = ['(' + squash + "|", ')?']; break;
}
return result + surroundPattern[0] + pattern + surroundPattern[1];
Expand Down
1 change: 1 addition & 0 deletions test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ describe("urlMatcherFactory", function () {
params: { id: { value: null, squash: true } }
});
expect(m.exec('/users/1138')).toEqual({ id: 1138 });
expect(m.exec('/users1138')).toBeNull();
expect(m.exec('/users/').id).toBeNull();
expect(m.exec('/users').id).toBeNull();
});
Expand Down

0 comments on commit b5130bb

Please sign in to comment.