From 44ebfaea4589f8789b7e5ae5a731923776621627 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Thu, 17 Dec 2020 13:03:01 -0800 Subject: [PATCH] fix(array): Fix decoding of array-type query parameters Closes https://github.com/ui-router/angular/issues/867 --- src/url/urlMatcher.ts | 8 ++++++-- test/urlMatcherFactorySpec.ts | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/url/urlMatcher.ts b/src/url/urlMatcher.ts index 218994cc..599cccbd 100644 --- a/src/url/urlMatcher.ts +++ b/src/url/urlMatcher.ts @@ -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); diff --git a/test/urlMatcherFactorySpec.ts b/test/urlMatcherFactorySpec.ts index 96f60ede..a4a794ca 100644 --- a/test/urlMatcherFactorySpec.ts +++ b/test/urlMatcherFactorySpec.ts @@ -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¶m1=%2F'); + expect(m.exec($location.path(), $location.search())).toEqual({ param1: ['%', '/'] }); + }); }); describe('multivalue-path-parameters', function () {