Hanlde wildcard when assigning a weight to an exception

This commit is contained in:
ilyaigpetrov 2021-01-15 17:28:55 +00:00
parent 7dae51db8c
commit 9ef236d604

View File

@ -406,13 +406,26 @@
/******/ /******/
/******/ /* EXCEPTIONS START */ /******/ /* EXCEPTIONS START */
/******/ const dotHost = '.' + host; /******/ const dotHost = '.' + host;
/******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain); // TODO: handle wildcards.
/******/ const isHostInDomain = (domain, ifWild) => {
if (ifWild) {
return dotHost.endsWith(domain.substr(1));
}
return domain === host;
}
/******/ const domainReducer = (maxWeight, [domain, ifProxy]) => { /******/ const domainReducer = (maxWeight, [domain, ifProxy]) => {
/******/ /******/
/******/ if (!isHostInDomain(domain)) { const ifWild = domain.startsWith('*.');
/******/ if (!isHostInDomain(domain, ifWild)) {
/******/ return maxWeight; /******/ return maxWeight;
/******/ } /******/ }
/******/ const newWeightAbs = domain.length; const len = domain.length;
if (ifWild) {
len = len === 0 ? len : (len - 2)*2 - 1;
} else {
len = len*2;
}
/******/ const newWeightAbs = len;
/******/ if (newWeightAbs < Math.abs(maxWeight)) { /******/ if (newWeightAbs < Math.abs(maxWeight)) {
/******/ return maxWeight; /******/ return maxWeight;
/******/ } /******/ }