Skip to content

Commit 39e8ceb

Browse files
Alison Galeatscott
authored andcommitted
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 <pete@bacondarwin.com> Simplify solution by replacing undefined with '' Co-Authored-By: Pete Bacon Darwin <pete@bacondarwin.com> 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
1 parent 448749c commit 39e8ceb

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/common/upgrade/src/params.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ export class AngularJSUrlCodec implements UrlCodec {
198198
// https://github.com/angular/angular.js/blob/864c7f0/src/ng/urlUtils.js#L60
199199
parse(url: string, base?: string) {
200200
try {
201-
const parsed = new URL(url, base);
201+
// Safari 12 throws an error when the URL constructor is called with an undefined base.
202+
const parsed = !base ? new URL(url) : new URL(url, base);
202203
return {
203204
href: parsed.href,
204205
protocol: parsed.protocol ? parsed.protocol.replace(/:$/, '') : '',
@@ -335,4 +336,4 @@ function encodeUriQuery(val: string, pctEncodeSpaces: boolean = false) {
335336
.replace(/%2C/gi, ',')
336337
.replace(/%3B/gi, ';')
337338
.replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
338-
}
339+
}

0 commit comments

Comments
 (0)