Skip to content

Commit

Permalink
fix($urlMatcherFactory): unquote all dashes from array params
Browse files Browse the repository at this point in the history
  • Loading branch information
cwmrowe committed Jan 29, 2015
1 parent 6cbee63 commit 06664d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ UrlMatcher.prototype.exec = function (path, searchParams) {

function decodePathArray(string) {
function reverseString(str) { return str.split("").reverse().join(""); }
function unquoteDashes(str) { return str.replace(/\\-/, "-"); }
function unquoteDashes(str) { return str.replace(/\\-/g, "-"); }

var split = reverseString(string).split(/-(?!\\)/);
var allReversed = map(split, reverseString);
Expand Down
7 changes: 7 additions & 0 deletions test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,21 @@ describe("UrlMatcher", function () {
expect(m.format({ "param1[]": [] })).toEqual("/foo/");
expect(m.format({ "param1[]": [ 'bar-' ] })).toEqual("/foo/bar%5C%2D");
expect(m.format({ "param1[]": [ 'bar-', '-baz' ] })).toEqual("/foo/bar%5C%2D-%5C%2Dbaz");
expect(m.format({ "param1[]": [ 'bar-bar-bar-', '-baz-baz-baz' ] }))
.toEqual("/foo/bar%5C%2Dbar%5C%2Dbar%5C%2D-%5C%2Dbaz%5C%2Dbaz%5C%2Dbaz");

// check that we handle $location.url decodes correctly
$location.url(m.format({ "param1[]": [ 'bar-', '-baz' ] }));
expect(m.exec($location.path(), $location.search())).toEqual({ "param1[]": [ 'bar-', '-baz' ] });

// check that we handle $location.url decodes correctly for multiple hyphens
$location.url(m.format({ "param1[]": [ 'bar-bar-bar-', '-baz-baz-baz' ] }));
expect(m.exec($location.path(), $location.search())).toEqual({ "param1[]": [ 'bar-bar-bar-', '-baz-baz-baz' ] });

// check that pre-encoded values are passed correctly
$location.url(m.format({ "param1[]": [ '%2C%20%5C%2C', '-baz' ] }));
expect(m.exec($location.path(), $location.search())).toEqual({ "param1[]": [ '%2C%20%5C%2C', '-baz' ] });

}));
});
});
Expand Down

0 comments on commit 06664d3

Please sign in to comment.