Skip to content

Commit f72871d

Browse files
committed
chore: add try/catch loop
we do this so that if there's a drift in validation we can still return a result
1 parent df9a80c commit f72871d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/shared/util/validation.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ export function isValidUrl(url: string, useWhitelist = false): boolean {
4848
if (!validator.isURL(url, URL_OPTS)) return false
4949

5050
// NOTE: check whether it's an IP
51-
const host = new URL(url).hostname
52-
return !validator.isIP(host)
51+
try {
52+
// NOTE: try/catch to avoid drifts in validation
53+
// between validator library and `URL` constructor
54+
const host = new URL(url).hostname
55+
return !validator.isIP(host)
56+
} catch {
57+
return false
58+
}
5359
}
5460

5561
// Tests if a short link consists of alphanumeric and hyphen characters.

0 commit comments

Comments
 (0)