fix: handle invalid URL parsing in useFeedSafeUrl hook (#4823)

Wrap new URL() constructor in try-catch to gracefully handle malformed URL strings that start with 'http' but are invalid. Returns null instead of throwing.

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
DIYgod
2026-01-30 13:48:23 +08:00
committed by GitHub
co-authored by Claude Haiku 4.5
parent d58720aae6
commit 62efdd29b2
@@ -31,8 +31,12 @@ export const useFeedSafeUrl = (entryId: string) => {
}
if (href.startsWith("http")) {
const domain = new URL(href).hostname
if (domain === "localhost") return null
try {
const domain = new URL(href).hostname
if (domain === "localhost") return null
} catch {
return null
}
return href
}