From 62efdd29b21fce9681e4e1497b6ab7084e5a41b0 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 30 Jan 2026 13:48:23 +0800 Subject: [PATCH] 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 --- .../layer/renderer/src/hooks/common/useFeedSafeUrl.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/desktop/layer/renderer/src/hooks/common/useFeedSafeUrl.ts b/apps/desktop/layer/renderer/src/hooks/common/useFeedSafeUrl.ts index 37ecc983e..5aa335882 100644 --- a/apps/desktop/layer/renderer/src/hooks/common/useFeedSafeUrl.ts +++ b/apps/desktop/layer/renderer/src/hooks/common/useFeedSafeUrl.ts @@ -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 }