From 832fad5035e59810e905c713fb43633e46725af2 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Sun, 11 Jan 2026 18:29:52 +0100 Subject: [PATCH] fix: handle malformed og:url protocols missing colon Some websites return og:url values like 'https//example.com' (missing colon after protocol). These get treated as relative URLs and concatenated with the base URL, creating broken links. This fix: - Adds fixMalformedUrl() to correct 'https//' -> 'https://' - Improves URL validation regex to require proper protocol - Validates the corrected URL before using it --- app/utils/rssHandler.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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);