From 3c21057f412e0533f567b898fac850e3530b2336 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 24 Sep 2026 16:47:17 -0700 Subject: [PATCH] Fix whitespace only urls --- src/widgets/feed/utils.js | 5 +++-- src/widgets/feed/utils.test.js | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/widgets/feed/utils.js b/src/widgets/feed/utils.js index 65f2a25ef..c43879220 100644 --- a/src/widgets/feed/utils.js +++ b/src/widgets/feed/utils.js @@ -11,9 +11,10 @@ function getText(node) { } export function httpUrl(value, baseUrl) { - if (!value) return null; + const trimmed = value?.trim(); + if (!trimmed) return null; try { - const url = new URL(value.trim(), baseUrl); + const url = new URL(trimmed, baseUrl); return ["http:", "https:"].includes(url.protocol) ? url.href : null; } catch { return null; diff --git a/src/widgets/feed/utils.test.js b/src/widgets/feed/utils.test.js index b83685f17..9694898ce 100644 --- a/src/widgets/feed/utils.test.js +++ b/src/widgets/feed/utils.test.js @@ -147,6 +147,8 @@ describe("widgets/feed/utils", () => { ["data:image/png;base64,AAAA", undefined, null], ["not a url", undefined, null], ["", undefined, null], + [" \n ", "https://a.com/feed", null], + [" /x ", "https://a.com/feed", "https://a.com/x"], ])("httpUrl(%j, %j) is %j", (value, base, expected) => { expect(httpUrl(value, base)).toBe(expected); });