Skip to content

Commit 44ebfae

Browse files
christopherthielenmergify[bot]
authored andcommitted
fix(array): Fix decoding of array-type query parameters
Closes ui-router/angular#867
1 parent 04a117f commit 44ebfae

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/url/urlMatcher.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,12 @@ export class UrlMatcher {
341341

342342
private _getDecodedParamValue(value: any, param: Param): any {
343343
if (isDefined(value)) {
344-
if (this.config.decodeParams && !param.type.raw && !isArray(value)) {
345-
value = decodeURIComponent(value);
344+
if (this.config.decodeParams && !param.type.raw) {
345+
if (isArray(value)) {
346+
value = value.map((paramValue) => decodeURIComponent(paramValue));
347+
} else {
348+
value = decodeURIComponent(value);
349+
}
346350
}
347351

348352
value = param.type.decode(value);

test/urlMatcherFactorySpec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ describe('UrlMatcher', function () {
449449
expect(m.exec($location.path(), $location.search())).toEqual({ param1: 'bar,baz' }); // coerced to string
450450
expect(m.format({ param1: ['bar', 'baz'] })).toBe('/foo?param1=bar%2Cbaz'); // coerced to string
451451
});
452+
453+
it('should decode query parameter values', function () {
454+
const m = $umf.compile('/foo?param1', { state: {} });
455+
$location.url('/foo?param1=%25&param1=%2F');
456+
expect(m.exec($location.path(), $location.search())).toEqual({ param1: ['%', '/'] });
457+
});
452458
});
453459

454460
describe('multivalue-path-parameters', function () {

0 commit comments

Comments
 (0)