mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-29 07:21:16 -07:00
Fix whitespace only urls
This commit is contained in:
@@ -11,9 +11,10 @@ function getText(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function httpUrl(value, baseUrl) {
|
export function httpUrl(value, baseUrl) {
|
||||||
if (!value) return null;
|
const trimmed = value?.trim();
|
||||||
|
if (!trimmed) return null;
|
||||||
try {
|
try {
|
||||||
const url = new URL(value.trim(), baseUrl);
|
const url = new URL(trimmed, baseUrl);
|
||||||
return ["http:", "https:"].includes(url.protocol) ? url.href : null;
|
return ["http:", "https:"].includes(url.protocol) ? url.href : null;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -147,6 +147,8 @@ describe("widgets/feed/utils", () => {
|
|||||||
["data:image/png;base64,AAAA", undefined, null],
|
["data:image/png;base64,AAAA", undefined, null],
|
||||||
["not a url", undefined, null],
|
["not a url", undefined, null],
|
||||||
["", 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) => {
|
])("httpUrl(%j, %j) is %j", (value, base, expected) => {
|
||||||
expect(httpUrl(value, base)).toBe(expected);
|
expect(httpUrl(value, base)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user