From 39e8ceb2cd729a63d24a6343087dfdacc2097604 Mon Sep 17 00:00:00 2001 From: Alison Gale Date: Wed, 2 Oct 2019 05:31:35 -0700 Subject: [PATCH] fix(upgrade): fix AngularJsUrlCodec to support Safari (#32959) Safari throws an error when the new URL() constructor is called with an undefined base. This change checks whether the base is undefined and then calls the corresponding version of the URL constructor. fix(upgrade): simplify solution by replacing undefined with '' Co-Authored-By: Pete Bacon Darwin Simplify solution by replacing undefined with '' Co-Authored-By: Pete Bacon Darwin fix(upgrade): Avoid passing an empty string as the base as well. Browsers other than Safari may have issues with the empty string. PR Close #32959 --- packages/common/upgrade/src/params.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/common/upgrade/src/params.ts b/packages/common/upgrade/src/params.ts index 025c2edcaa..d1f7917ff6 100644 --- a/packages/common/upgrade/src/params.ts +++ b/packages/common/upgrade/src/params.ts @@ -198,7 +198,8 @@ export class AngularJSUrlCodec implements UrlCodec { // https://github.com/angular/angular.js/blob/864c7f0/src/ng/urlUtils.js#L60 parse(url: string, base?: string) { try { - const parsed = new URL(url, base); + // Safari 12 throws an error when the URL constructor is called with an undefined base. + const parsed = !base ? new URL(url) : new URL(url, base); return { href: parsed.href, protocol: parsed.protocol ? parsed.protocol.replace(/:$/, '') : '', @@ -335,4 +336,4 @@ function encodeUriQuery(val: string, pctEncodeSpaces: boolean = false) { .replace(/%2C/gi, ',') .replace(/%3B/gi, ';') .replace(/%20/g, (pctEncodeSpaces ? '%20' : '+')); -} \ No newline at end of file +}