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
parent d58720aae6
commit 62efdd29b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 2 deletions

View File

@ -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
}