mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-27 14:31:17 -07:00
Fix whitespace only urls
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user