Skip to content

Commit

Permalink
fix(array): Fix decoding of array-type query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen authored and mergify[bot] committed Dec 17, 2020
1 parent 04a117f commit 44ebfae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/url/urlMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,12 @@ export class UrlMatcher {

private _getDecodedParamValue(value: any, param: Param): any {
if (isDefined(value)) {
if (this.config.decodeParams && !param.type.raw && !isArray(value)) {
value = decodeURIComponent(value);
if (this.config.decodeParams && !param.type.raw) {
if (isArray(value)) {
value = value.map((paramValue) => decodeURIComponent(paramValue));
} else {
value = decodeURIComponent(value);
}
}

value = param.type.decode(value);
Expand Down
6 changes: 6 additions & 0 deletions test/urlMatcherFactorySpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@ describe('UrlMatcher', function () {
expect(m.exec($location.path(), $location.search())).toEqual({ param1: 'bar,baz' }); // coerced to string
expect(m.format({ param1: ['bar', 'baz'] })).toBe('/foo?param1=bar%2Cbaz'); // coerced to string
});

it('should decode query parameter values', function () {
const m = $umf.compile('/foo?param1', { state: {} });
$location.url('/foo?param1=%25&param1=%2F');
expect(m.exec($location.path(), $location.search())).toEqual({ param1: ['%', '/'] });
});
});

describe('multivalue-path-parameters', function () {
Expand Down

0 comments on commit 44ebfae

Please sign in to comment.