From 9495910261434a818beacf57381bfa424573b633 Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Tue, 31 Oct 2017 21:08:12 +0500 Subject: [PATCH] Move proxy scheme parsing to utils --- .../src/extension-common/00-init-apis.js | 34 +++++++++++++++++++ .../extension-common/35-pac-kitchen-api.js | 3 ++ .../options/src/components/ProxyEditor.js | 19 ++++------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/00-init-apis.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/00-init-apis.js index 9c53e7a..1b1566c 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/00-init-apis.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/00-init-apis.js @@ -196,6 +196,40 @@ }, + parseProxyScheme(proxyAsStringRaw) { + + const proxyAsString = proxyAsStringRaw.trim(); + const [type] = proxyAsString.split(/\s+/); + /* + if (!/^[a-zA-Z0-9]+$/.test(type)) { + throw new Error(`${type} is not a proxy type!`); + } + JS has no code blocks in RE, seems safe to omit this check. + */ + const typeRe = new RegExp(`^${type}\\s+`, 'g'); + const crededAddr = proxyAsString.replace(typeRe, ''); + + let parts; + parts = crededAddr.split('@'); + let [creds, addr] = [parts.slice(0, -1).join('@'), parts[parts.length - 1]]; + + const [hostname, port] = addr.split(':'); + + parts = creds.split(':') + const username = parts[0]; + const password = parts.slice(1).join(':'); + + return { + type, + username, + password, + hostname, + port, + creds, + } + + }, + }; const max = 2**16; 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 3b393d5..aec2870 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 @@ -240,6 +240,9 @@ customProxyArray.push(...self.torPoints); } + // Hanlde protected proxies in customProxyArray. + // TODO: + self.filteredCustomsString = ''; if (customProxyArray.length) { self.customProxyArray = customProxyArray; 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 94aecda..4b5c63e 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 @@ -331,21 +331,14 @@ export default function getProxyEditor(theState) { splitBySemi(this.props.proxyStringRaw).map((proxyAsStringRaw, index) => { const proxyAsString = proxyAsStringRaw.trim(); - const [type] = proxyAsString.split(/\s+/); - /* - if (!/^[a-zA-Z0-9]+$/.test(type)) { - throw new Error(`${type} is not a proxy type!`); - } - JS has no code blocks in RE, seems safe to omit this check. - */ - const typeRe = new RegExp(`^${type}\s+`, 'g'); - const crededAddr = proxyAsString.replace(typeRe, ''); - let parts; - parts = crededAddr.split('@'); - let [creds, addr] = [parts.slice(0, -1).join('@'), parts[parts.length - 1]]; + const { + type, + creds, + hostname, + port, + } = theState.utils.parseProxyScheme(proxyAsString); - const [hostname, port] = addr.split(':'); return (