From 0f0c1b22abe8ae64245a4672dddca25c415c406c Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sat, 2 Mar 2024 22:21:49 +0100 Subject: [PATCH] Prepare web root postfix adding functionality for double slash URL support --- svr.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/svr.js b/svr.js index 5e258f3..ba2e152 100644 --- a/svr.js +++ b/svr.js @@ -4369,10 +4369,11 @@ if (!cluster.isPrimary) { // Add web root postfixes if (!isProxy) { - var urlWithPostfix = req.url; + var preparedReqUrl3 = (postFixEntry.allowDoubleSlashes ? (href.replace(/\/+/,"/") + (uobject.search ? uobject.search : "")) + (uobject.hash ? uobject.hash : "")) : req.url); + var urlWithPostfix = preparedReqUrl3; var postfixPrefix = ""; wwwrootPostfixPrefixesVHost.every(function (currentPostfixPrefix) { - if (req.url.indexOf(currentPostfixPrefix) == 0) { + if (preparedReqUrl3.indexOf(currentPostfixPrefix) == 0) { if (currentPostfixPrefix.match(/\/+$/)) postfixPrefix = currentPostfixPrefix.replace(/\/+$/, ""); else if (urlWithPostfix.length == currentPostfixPrefix.length || urlWithPostfix[currentPostfixPrefix.length] == "?" || urlWithPostfix[currentPostfixPrefix.length] == "/" || urlWithPostfix[currentPostfixPrefix.length] == "#") postfixPrefix = currentPostfixPrefix; else return true; @@ -4383,14 +4384,14 @@ if (!cluster.isPrimary) { } }); wwwrootPostfixesVHost.every(function (postfixEntry) { - if (matchHostname(postfixEntry.host) && ipMatch(postfixEntry.ip, req.socket ? req.socket.localAddress : undefined) && !(postfixEntry.skipRegex && req.url.match(createRegex(postfixEntry.skipRegex)))) { + if (matchHostname(postfixEntry.host) && ipMatch(postfixEntry.ip, req.socket ? req.socket.localAddress : undefined) && !(postfixEntry.skipRegex && preparedReqUrl3.match(createRegex(postfixEntry.skipRegex)))) { urlWithPostfix = postfixPrefix + "/" + postfixEntry.postfix + urlWithPostfix; return false; } else { return true; } }); - if (urlWithPostfix != req.url) { + if (urlWithPostfix != preparedReqUrl3) { serverconsole.resmessage("Added web root postfix: " + req.url + " => " + urlWithPostfix); req.url = urlWithPostfix; uobject = parseURL(req.url);