Skip to content
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: 2 additions & 0 deletions src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ UrlMatcher.prototype.exec = function (path, searchParams) {
nPath = this.segments.length-1,
values = {}, i;

if (nPath !== m.length - 1) throw new Error("Unbalanced capture group in route '" + this.source + "'");

for (i=0; i<nPath; i++) values[params[i]] = decodeURIComponent(m[i+1]);
for (/**/; i<nTotal; i++) values[params[i]] = searchParams[params[i]];

Expand Down
22 changes: 22 additions & 0 deletions test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ describe("UrlMatcher", function () {
.toBeNull();
});

it('.exec() throws on unbalanced capture list', function () {
var shouldThrow = {
"/url/{matchedParam:([a-z]+)}/child/{childParam}": '/url/someword/child/childParam',
"/url/{matchedParam:([a-z]+)}/child/{childParam}?foo": '/url/someword/child/childParam'
};

angular.forEach(shouldThrow, function(url, route) {
expect(function() { new UrlMatcher(route).exec(url, {}); }).toThrow(
"Unbalanced capture group in route '" + route + "'"
);
});

var shouldPass = {
"/url/{matchedParam:[a-z]+}/child/{childParam}": '/url/someword/child/childParam',
"/url/{matchedParam:[a-z]+}/child/{childParam}?foo": '/url/someword/child/childParam'
};

angular.forEach(shouldPass, function(url, route) {
expect(function() { new UrlMatcher(route).exec(url, {}); }).not.toThrow();
});
});

it(".format() reconstitutes the URL", function () {
expect(
new UrlMatcher('/users/:id/details/{type}/{repeat:[0-9]+}?from')
Expand Down