From 7dae51db8cdcb49615425ffc8b67eaded061459c Mon Sep 17 00:00:00 2001 From: ilyaigpetrov Date: Fri, 15 Jan 2021 16:54:10 +0000 Subject: [PATCH] Return to a step back when wildcard is present in the key (not in the value) --- .../src/extension-common/35-pac-kitchen-api.js | 15 +++++++-------- .../pages/options/src/components/ExcEditor.js | 16 +++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js index c05016a..acdb33b 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js @@ -298,20 +298,19 @@ self.included = []; self.excluded = []; for(const host of Object.keys(self.exceptions)) { - const ifProxy = self.exceptions[host]?.ifProxy || false; - const ifWild = self.exceptions[host]?.ifWild || false; + const ifProxy = self.exceptions[host] || false; if (ifProxy) { - self.included.push([host, ifWild]); + self.included.push(host); } else { - self.excluded.push([host, ifWild]); + self.excluded.push(host); } } ['included', 'excluded'].forEach((who) => { self[who] = self[who] - .map( ([domain, ifWild]) => [domain.split('').reverse(), ifWild] ) + .map( (domain) => domain.split('').reverse() ) .sort() - .map( ([rDomain, ifWild]) => [rDomain.reverse().join(''), ifWild] ); + .map( (rDomain) => rDomain.reverse().join('') ); }); if (self.included.length && !self.filteredCustomsString) { @@ -392,7 +391,7 @@ if (pacMods.ifProxyMoreDomains) { finalExceptions = pacMods.moreDomains.reduce((acc, tld) => { - acc[tld] = { ifProxy: true, ifWild: true }; + acc['*.' + tld] = true; return acc; }, finalExceptions); @@ -408,7 +407,7 @@ /******/ /* EXCEPTIONS START */ /******/ const dotHost = '.' + host; /******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain); -/******/ const domainReducer = (maxWeight, [domain, { ifProxy, ifWild }]) => { +/******/ const domainReducer = (maxWeight, [domain, ifProxy]) => { /******/ /******/ if (!isHostInDomain(domain)) { /******/ return maxWeight; diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ExcEditor.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ExcEditor.js index ae424e8..f33a340 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ExcEditor.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ExcEditor.js @@ -62,9 +62,6 @@ export default function getExcEditor(theState) { }; */ - - const unWild = (inputExpr) => inputExpr.replace(/^\*\./g, ''); - return class ExcEditor extends Component { modsToOpts(pacMods) { @@ -88,7 +85,6 @@ export default function getExcEditor(theState) { const pacMods = props.apis.pacKitchen.getPacMods(); this.state = { trimmedInputValueOrSpace, - inputHostname: unWild(trimmedInputValueOrSpace), sortedListOfOptions: this.modsToOpts(pacMods), hostToIfHidden: {}, }; @@ -114,7 +110,7 @@ export default function getExcEditor(theState) { isHostValid(host) { - const ValidHostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; + const ValidHostnameRegex = /^(?:\*\.)?(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; if(!ValidHostnameRegex.test(host)) { this.props.funs.showErrors(new TypeError('Должно быть только доменное имя, без протокола, порта и пути. Попробуйте ещё раз.')); return false; @@ -125,8 +121,7 @@ export default function getExcEditor(theState) { handleRadioClick(event) { - const ifWild = this.state.trimmedInputValueOrSpace.startsWith('*.'); - const host = this.state.inputHostname; + const host = this.state.trimmedInputValueOrSpace; (() => { // `return` === `preventDefault`. if(!this.isHostValid(host)) { @@ -152,7 +147,7 @@ export default function getExcEditor(theState) { return false; } - pacMods.exceptions[host] = { ifProxy: ifYesClicked, ifWild }; + pacMods.exceptions[host] = ifYesClicked; break; default: @@ -217,7 +212,6 @@ export default function getExcEditor(theState) { setInputValue(currentHost); this.setState({ trimmedInputValueOrSpace: currentHost, - inputHostname: unWild(currentHost), }); // Episode 2. @@ -300,7 +294,7 @@ export default function getExcEditor(theState) { if ( acc !== undefined ) { return acc; } - return this.state.inputHostname === excHost ? (excState || {}).ifProxy : undefined; + return this.state.trimmedInputValueOrSpace === excHost ? excState : undefined; }, undefined); @@ -329,7 +323,7 @@ export default function getExcEditor(theState) { // 1. Option's value may be changed to hide it from the tooltip. // 2. Space is used in matching so even an empty input (replaced with space) has tooltip with prompts. - const ifProxy = (excState || {}).ifProxy; + const ifProxy = excState; return