Skip to content

Commit 06664d3

Browse files
committed
fix($urlMatcherFactory): unquote all dashes from array params
1 parent 6cbee63 commit 06664d3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/urlMatcherFactory.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ UrlMatcher.prototype.exec = function (path, searchParams) {
242242

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

247247
var split = reverseString(string).split(/-(?!\\)/);
248248
var allReversed = map(split, reverseString);

test/urlMatcherFactorySpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,21 @@ describe("UrlMatcher", function () {
390390
expect(m.format({ "param1[]": [] })).toEqual("/foo/");
391391
expect(m.format({ "param1[]": [ 'bar-' ] })).toEqual("/foo/bar%5C%2D");
392392
expect(m.format({ "param1[]": [ 'bar-', '-baz' ] })).toEqual("/foo/bar%5C%2D-%5C%2Dbaz");
393+
expect(m.format({ "param1[]": [ 'bar-bar-bar-', '-baz-baz-baz' ] }))
394+
.toEqual("/foo/bar%5C%2Dbar%5C%2Dbar%5C%2D-%5C%2Dbaz%5C%2Dbaz%5C%2Dbaz");
393395

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

400+
// check that we handle $location.url decodes correctly for multiple hyphens
401+
$location.url(m.format({ "param1[]": [ 'bar-bar-bar-', '-baz-baz-baz' ] }));
402+
expect(m.exec($location.path(), $location.search())).toEqual({ "param1[]": [ 'bar-bar-bar-', '-baz-baz-baz' ] });
403+
398404
// check that pre-encoded values are passed correctly
399405
$location.url(m.format({ "param1[]": [ '%2C%20%5C%2C', '-baz' ] }));
400406
expect(m.exec($location.path(), $location.search())).toEqual({ "param1[]": [ '%2C%20%5C%2C', '-baz' ] });
407+
401408
}));
402409
});
403410
});

0 commit comments

Comments
 (0)