Return to a step back when wildcard is present in the key (not in the value)

This commit is contained in:
ilyaigpetrov 2021-01-15 16:54:10 +00:00
parent 796681ae5a
commit 7dae51db8c
2 changed files with 12 additions and 19 deletions

View File

@ -298,20 +298,19 @@
self.included = []; self.included = [];
self.excluded = []; self.excluded = [];
for(const host of Object.keys(self.exceptions)) { for(const host of Object.keys(self.exceptions)) {
const ifProxy = self.exceptions[host]?.ifProxy || false; const ifProxy = self.exceptions[host] || false;
const ifWild = self.exceptions[host]?.ifWild || false;
if (ifProxy) { if (ifProxy) {
self.included.push([host, ifWild]); self.included.push(host);
} else { } else {
self.excluded.push([host, ifWild]); self.excluded.push(host);
} }
} }
['included', 'excluded'].forEach((who) => { ['included', 'excluded'].forEach((who) => {
self[who] = self[who] self[who] = self[who]
.map( ([domain, ifWild]) => [domain.split('').reverse(), ifWild] ) .map( (domain) => domain.split('').reverse() )
.sort() .sort()
.map( ([rDomain, ifWild]) => [rDomain.reverse().join(''), ifWild] ); .map( (rDomain) => rDomain.reverse().join('') );
}); });
if (self.included.length && !self.filteredCustomsString) { if (self.included.length && !self.filteredCustomsString) {
@ -392,7 +391,7 @@
if (pacMods.ifProxyMoreDomains) { if (pacMods.ifProxyMoreDomains) {
finalExceptions = pacMods.moreDomains.reduce((acc, tld) => { finalExceptions = pacMods.moreDomains.reduce((acc, tld) => {
acc[tld] = { ifProxy: true, ifWild: true }; acc['*.' + tld] = true;
return acc; return acc;
}, finalExceptions); }, finalExceptions);
@ -408,7 +407,7 @@
/******/ /* EXCEPTIONS START */ /******/ /* EXCEPTIONS START */
/******/ const dotHost = '.' + host; /******/ const dotHost = '.' + host;
/******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain); /******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain);
/******/ const domainReducer = (maxWeight, [domain, { ifProxy, ifWild }]) => { /******/ const domainReducer = (maxWeight, [domain, ifProxy]) => {
/******/ /******/
/******/ if (!isHostInDomain(domain)) { /******/ if (!isHostInDomain(domain)) {
/******/ return maxWeight; /******/ return maxWeight;

View File

@ -62,9 +62,6 @@ export default function getExcEditor(theState) {
}; };
*/ */
const unWild = (inputExpr) => inputExpr.replace(/^\*\./g, '');
return class ExcEditor extends Component { return class ExcEditor extends Component {
modsToOpts(pacMods) { modsToOpts(pacMods) {
@ -88,7 +85,6 @@ export default function getExcEditor(theState) {
const pacMods = props.apis.pacKitchen.getPacMods(); const pacMods = props.apis.pacKitchen.getPacMods();
this.state = { this.state = {
trimmedInputValueOrSpace, trimmedInputValueOrSpace,
inputHostname: unWild(trimmedInputValueOrSpace),
sortedListOfOptions: this.modsToOpts(pacMods), sortedListOfOptions: this.modsToOpts(pacMods),
hostToIfHidden: {}, hostToIfHidden: {},
}; };
@ -114,7 +110,7 @@ export default function getExcEditor(theState) {
isHostValid(host) { 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)) { if(!ValidHostnameRegex.test(host)) {
this.props.funs.showErrors(new TypeError('Должно быть только доменное имя, без протокола, порта и пути. Попробуйте ещё раз.')); this.props.funs.showErrors(new TypeError('Должно быть только доменное имя, без протокола, порта и пути. Попробуйте ещё раз.'));
return false; return false;
@ -125,8 +121,7 @@ export default function getExcEditor(theState) {
handleRadioClick(event) { handleRadioClick(event) {
const ifWild = this.state.trimmedInputValueOrSpace.startsWith('*.'); const host = this.state.trimmedInputValueOrSpace;
const host = this.state.inputHostname;
(() => { // `return` === `preventDefault`. (() => { // `return` === `preventDefault`.
if(!this.isHostValid(host)) { if(!this.isHostValid(host)) {
@ -152,7 +147,7 @@ export default function getExcEditor(theState) {
return false; return false;
} }
pacMods.exceptions[host] = { ifProxy: ifYesClicked, ifWild }; pacMods.exceptions[host] = ifYesClicked;
break; break;
default: default:
@ -217,7 +212,6 @@ export default function getExcEditor(theState) {
setInputValue(currentHost); setInputValue(currentHost);
this.setState({ this.setState({
trimmedInputValueOrSpace: currentHost, trimmedInputValueOrSpace: currentHost,
inputHostname: unWild(currentHost),
}); });
// Episode 2. // Episode 2.
@ -300,7 +294,7 @@ export default function getExcEditor(theState) {
if ( acc !== undefined ) { if ( acc !== undefined ) {
return acc; return acc;
} }
return this.state.inputHostname === excHost ? (excState || {}).ifProxy : undefined; return this.state.trimmedInputValueOrSpace === excHost ? excState : undefined;
}, undefined); }, undefined);
@ -329,7 +323,7 @@ export default function getExcEditor(theState) {
// 1. Option's value may be changed to hide it from the tooltip. // 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. // 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 <option return <option
value={ this.state.hostToIfHidden[excHost] ? '\n' : excHost + ' ' } value={ this.state.hostToIfHidden[excHost] ? '\n' : excHost + ' ' }
label={ ifProxy === true ? labelIfProxied : (ifProxy === false ? labelIfNotProxied : labelIfAuto) }/> label={ ifProxy === true ? labelIfProxied : (ifProxy === false ? labelIfNotProxied : labelIfAuto) }/>