diff --git a/core/src/global/config.ts b/core/src/global/config.ts index e79de89865..47fbf3b191 100644 --- a/core/src/global/config.ts +++ b/core/src/global/config.ts @@ -60,7 +60,13 @@ export const configFromURL = (win: Window) => { .slice(1) .split('&') .map((entry) => entry.split('=')) - .map(([key, value]) => [decodeURIComponent(key), decodeURIComponent(value)]) + .map(([key, value]) => { + try { + return [decodeURIComponent(key), decodeURIComponent(value)]; + } catch (e) { + return ['', '']; + } + }) .filter(([key]) => startsWith(key, IONIC_PREFIX)) .map(([key, value]) => [key.slice(IONIC_PREFIX.length), value]) .forEach(([key, value]) => { diff --git a/core/src/global/test/config-controller.spec.ts b/core/src/global/test/config-controller.spec.ts index 7550c5fc0a..0be7fec0ae 100644 --- a/core/src/global/test/config-controller.spec.ts +++ b/core/src/global/test/config-controller.spec.ts @@ -1,5 +1,5 @@ import type { IonicConfig } from '../../interface'; -import { Config } from '../config'; +import { Config, configFromURL } from '../config'; describe('Config', () => { it('should get a value from the config', () => { @@ -82,4 +82,16 @@ describe('Config', () => { config.set('text0' as any, 'hola'); expect(config.get('text0' as any, 'HEY')).toEqual('hola'); }); + + it('should not throw an exception with a malformed URI', () => { + // https://github.com/ionic-team/ionic-framework/issues/29479 + + expect( + configFromURL({ + location: { + search: '?test=%', + }, + } as unknown as Window) + ).toEqual({}); + }); });