From e4bf2292b45cff5a9840deb438f1d6c2eb9bf401 Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Tue, 31 Oct 2017 21:20:56 +0500 Subject: [PATCH] Fix sanitizing logic to use new utils parser --- .../options/src/components/ProxyEditor.js | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js index 4b5c63e..76c9cf0 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js @@ -403,16 +403,18 @@ export default function getProxyEditor(theState) { const errors = splitBySemi(this.state.stashedExports) .map((proxyAsString) => { - const [rawType, crededAddr, ...rest] = proxyAsString.split(/\s+/); - if (rest && rest.length) { - return new Error( - `"${rest.join(', ')}" кажется мне лишним. Вы забыли ";"?` - ); - } + const { + type, + creds, + hostname, + port, + } = theState.utils.parseProxyScheme(proxyAsString); + const crededAddr = `${creds ? `${creds}@` : ''}${hostname}:${port}`; + const knownTypes = PROXY_TYPE_LABEL_PAIRS.map(([type, label]) => type); - if( !knownTypes.includes(rawType.toUpperCase()) ) { + if( !knownTypes.includes(type.toUpperCase()) ) { return new Error( - `Неверный тип ${rawType}. Известные типы: ${knownTypes.join(', ')}.` + `Неверный тип ${type}. Известные типы: ${knownTypes.join(', ')}.` ); } if (!(crededAddr && /^(?:[^@]+@)?[^:]+:\d+$/.test(crededAddr))) { @@ -420,16 +422,10 @@ export default function getProxyEditor(theState) { `Адрес прокси "${crededAddr || ''}" не соответствует формату "<опц_логин>:<опц_пароль>@<домен_или_IP>:<порт_из_цифр>".` ); } - let [creds, addr] = crededAddr.split('@'); - if (!addr) { - addr = creds; - creds = ''; - } - const [hostname, rawPort] = addr.split(':'); - const port = parseInt(rawPort); - if (port < 0 || port > 65535) { + const portInt = parseInt(port); + if (portInt < 0 || portInt > 65535) { return new Error( - `Порт "${rawPort}" должен быть целым числом от 0 до 65535.` + `Порт "${port}" должен быть целым числом от 0 до 65535.` ); } return false;