Skip to content

Commit 58dce1c

Browse files
committed
refactor: use URL.parse()
1 parent da410ad commit 58dce1c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

shared/utils/url.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@ export function areUrlsEquivalent(url1: string, url2: string): boolean {
3030
export function getSafeHttpUrl(url?: string | null): string | null {
3131
if (!url) return null
3232

33-
try {
34-
const parsed = new URL(url)
35-
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
36-
return null
37-
}
38-
39-
return parsed.href
40-
} catch {
33+
const parsed = URL.parse(url)
34+
if (!parsed || (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')) {
4135
return null
4236
}
37+
38+
return parsed.href
4339
}
4440

4541
export function normalizeSearchParam(query?: LocationQueryValue | LocationQueryValue[]): string {

0 commit comments

Comments
 (0)