From 98a9ae660d7b6e0bd4bcc3a9b8245af5bd2b0dbb Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 18 Oct 2023 08:41:27 -0400 Subject: [PATCH] fix: better handle the requested url by only using pathname and hostname --- src/backend/filters/urlRewrite.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/filters/urlRewrite.ts b/src/backend/filters/urlRewrite.ts index b881726..ae0c96d 100644 --- a/src/backend/filters/urlRewrite.ts +++ b/src/backend/filters/urlRewrite.ts @@ -20,6 +20,8 @@ export default class URLRewriteFilter implements ContentFilter { const $ = cheerio.load(html); + const rUrl = new URL(requestor); + ["a", "link", "script", "img"].forEach((tag) => { $.root() .find(tag) @@ -31,9 +33,9 @@ export default class URLRewriteFilter implements ContentFilter { if (!isExternal || !isICANN(urlValue)) { if (!isExternal) { //@ts-ignore - urlValue = path.join(requestor, urlValue); + urlValue = path.join(rUrl.pathname, urlValue); } - urlValue = `${swUrl.protocol}//${swUrl.hostname}/browse/${urlValue}`; + urlValue = `${swUrl.protocol}//${swUrl.hostname}/browse/${rUrl.hostname}${urlValue}`; console.log(urlValue); $(element).attr(attrName, urlValue);