Take creds, don't repsect old ; with no \n

This commit is contained in:
Ilya Ig. Petrov 2017-10-31 19:20:16 +05:00
parent 18d3dda63e
commit b0f9cd2694

View File

@ -161,7 +161,7 @@ export default function getProxyEditor(theState) {
const splitBySemi = (proxyString) => proxyString const splitBySemi = (proxyString) => proxyString
.replace(/#.*$/mg, '') .replace(/#.*$/mg, '')
.trim() .trim()
.split(/\s*;\s*/g) .split(/\s*;\r?\n\s*/g)
.map((s) => s.trim()) .map((s) => s.trim())
.filter((s) => s); .filter((s) => s);
@ -227,7 +227,7 @@ export default function getProxyEditor(theState) {
const port = elements.newPort; const port = elements.newPort;
const newValue = `${that.props.proxyStringRaw};\n${type} ${crededHostname}:${port}` const newValue = `${that.props.proxyStringRaw};\n${type} ${crededHostname}:${port}`
.trim().replace(/(\s*;\s*)+/, ';\n'); .trim().replace(/(\s*;\n\s*)+/, ';\n');
that.props.setProxyStringRaw(true, newValue); that.props.setProxyStringRaw(true, newValue);
} }
@ -331,11 +331,10 @@ export default function getProxyEditor(theState) {
splitBySemi(this.props.proxyStringRaw).map((proxyAsString, index) => { splitBySemi(this.props.proxyStringRaw).map((proxyAsString, index) => {
const [type, crededAddr] = proxyAsString.trim().split(/\s+/); const [type, crededAddr] = proxyAsString.trim().split(/\s+/);
let [creds, addr] = crededAddr.split('@'); let parts;
if (!addr) { parts = crededAddr.split('@');
addr = creds; let [creds, addr] = [parts.slice(0, -1).join('@'), parts[parts.length - 1]];
creds = '';
}
const [hostname, port] = addr.split(':'); const [hostname, port] = addr.split(':');
return ( return (
<tr class={scopedCss.proxyRow}> <tr class={scopedCss.proxyRow}>
@ -511,7 +510,7 @@ PROXY foobar.com:8080; # Not HTTP!`.trim()}
value={ value={
this.state.stashedExports !== false this.state.stashedExports !== false
? this.state.stashedExports ? this.state.stashedExports
: (this.props.proxyStringRaw || '').replace(/\s*;\s*/g, ';\n') : (this.props.proxyStringRaw || '').replace(/\s*;\n\s*/g, ';\n')
} }
/></td> /></td>
</tr> </tr>
@ -530,10 +529,12 @@ PROXY foobar.com:8080; # Not HTTP!`.trim()}
return proxyStringRaw return proxyStringRaw
.replace(/#.*$/mg, '') // Strip comments. .replace(/#.*$/mg, '') // Strip comments.
.replace(/[^\S\r\n]*DIRECT[^\S\r\n]*/g, '') // Remove DIRECT from old versions. .replace(/[^\S\r\n]*DIRECT[^\S\r\n]*/g, '') // Remove DIRECT from old versions.
/*
.split( /(?:[^\S\r\n]*(?:;|\r?\n)+[^\S\r\n]*)+/g ) .split( /(?:[^\S\r\n]*(?:;|\r?\n)+[^\S\r\n]*)+/g )
.map( (p) => p.trim() ) .map( (p) => p.trim() )
.filter((p) => p) .filter((p) => p)
.join(';\n'); .join(';\n');
*/
}; };