isGitHub(url) rejects invalid URLs

This commit is contained in:
tcely 2026-03-14 19:50:39 -04:00
parent 4f1ce51cf0
commit 82d68e7628
No known key found for this signature in database
GPG Key ID: 9F1DAF9D9070430F

View File

@ -34,7 +34,13 @@ export function gitHubAssetDownloadUrl(
} }
export function isGitHub(url: string, api: boolean = false): boolean { export function isGitHub(url: string, api: boolean = false): boolean {
const parsedUrl = new URL(url); let parsedUrl: URL;
try {
parsedUrl = new URL(url);
} catch {
return false;
}
if (api) { if (api) {
return "api.github.com" === parsedUrl.hostname; return "api.github.com" === parsedUrl.hostname;
} }