fix: better handle the requested url by only using pathname and hostname

This commit is contained in:
Derrick Hammer 2023-10-18 08:41:27 -04:00
parent 52c11f350e
commit 98a9ae660d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 4 additions and 2 deletions

View File

@ -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);