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); });