Move proxy scheme parsing to utils

This commit is contained in:
Ilya Ig. Petrov 2017-10-31 21:08:12 +05:00
parent bc439c22f7
commit 9495910261
3 changed files with 43 additions and 13 deletions

View File

@ -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; const max = 2**16;

View File

@ -240,6 +240,9 @@
customProxyArray.push(...self.torPoints); customProxyArray.push(...self.torPoints);
} }
// Hanlde protected proxies in customProxyArray.
// TODO:
self.filteredCustomsString = ''; self.filteredCustomsString = '';
if (customProxyArray.length) { if (customProxyArray.length) {
self.customProxyArray = customProxyArray; self.customProxyArray = customProxyArray;

View File

@ -331,21 +331,14 @@ export default function getProxyEditor(theState) {
splitBySemi(this.props.proxyStringRaw).map((proxyAsStringRaw, index) => { splitBySemi(this.props.proxyStringRaw).map((proxyAsStringRaw, index) => {
const proxyAsString = proxyAsStringRaw.trim(); 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; const {
parts = crededAddr.split('@'); type,
let [creds, addr] = [parts.slice(0, -1).join('@'), parts[parts.length - 1]]; creds,
hostname,
port,
} = theState.utils.parseProxyScheme(proxyAsString);
const [hostname, port] = addr.split(':');
return ( return (
<tr class={scopedCss.proxyRow}> <tr class={scopedCss.proxyRow}>
<td> <td>