diff --git a/app/utils/rssHandler.ts b/app/utils/rssHandler.ts index 9646c14..a3e4de8 100644 --- a/app/utils/rssHandler.ts +++ b/app/utils/rssHandler.ts @@ -152,14 +152,16 @@ async function start() { description = removeHTMLTags(description); } - let uri = openGraphData.ogUrl ? openGraphData.ogUrl : url; + let uri = openGraphData.ogUrl + ? fixMalformedUrl(openGraphData.ogUrl) + : url; if (openGraphData.ogUrl) { let regexURL = new RegExp( - `(?:(h|H)(t|T)(t|T)(p|P)(s|):\\/\\/|)[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)` + `^(h|H)(t|T)(t|T)(p|P)(s|S)?:\\/\\/[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)` ); - if (!regexURL.test(openGraphData.ogUrl)) uri = url; + if (!regexURL.test(uri)) uri = url; } if (!uri || (!openGraphData.ogTitle && !item.title)) { @@ -319,6 +321,14 @@ function decodeHTML(htmlString: string) { return decode(decode(htmlString)); } +function fixMalformedUrl(urlString: string): string { + // Fix malformed protocols like "https//" or "http//" (missing colon) + // These get treated as relative URLs and cause concatenation bugs + return urlString + .replace(/^https\/\//i, "https://") + .replace(/^http\/\//i, "http://"); +} + async function resizeImageToBuffer(bufferData: Buffer) { try { const image = await jimp.read(bufferData);