Fix whitespace only urls

This commit is contained in:
shamoon
2026-09-24 16:47:17 -07:00
parent 9cbd0b2e24
commit 3c21057f41
2 changed files with 5 additions and 2 deletions
+3 -2
View File
@@ -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;
+2
View File
@@ -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);
});