ssh-config
Advanced tools
Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2
46
index.js
@@ -151,2 +151,10 @@ 'use strict' | ||
const formatValue = (value, quoted) => { | ||
if (Array.isArray(value)) { | ||
return value.map(chunk => formatValue(chunk, RE_SPACE.test(chunk))).join(' ') | ||
} | ||
return quoted ? `"${value}"` : value | ||
} | ||
const format = line => { | ||
@@ -159,5 +167,6 @@ str += line.before | ||
else if (line.type === DIRECTIVE) { | ||
str += line.quoted || (line.param == 'IdentityFile' && RE_SPACE.test(line.value)) | ||
? `${line.param}${line.separator}"${line.value}"` | ||
: `${line.param}${line.separator}${line.value}` | ||
const quoted = line.quoted | ||
|| (/IdentityFile/i.test(line.param) && RE_SPACE.test(line.value)) | ||
const value = formatValue(line.value, quoted) | ||
str += `${line.param}${line.separator}${value}` | ||
} | ||
@@ -248,2 +257,3 @@ | ||
while (chr && !RE_LINE_BREAK.test(chr)) { | ||
// backslash escapes only double quotes | ||
if (escaped) { | ||
@@ -253,3 +263,4 @@ val += chr === '"' ? chr : `\\${chr}` | ||
} | ||
else if (chr === '"') { | ||
// ProxyCommand ssh -W "%h:%p" firewall.example.org | ||
else if (chr === '"' && (!val || quoted)) { | ||
quoted = !quoted | ||
@@ -266,3 +277,6 @@ } | ||
if (quoted || escaped) throw new Error('Unexpected line break') | ||
if (quoted || escaped) { | ||
throw new Error(`Unexpected line break at ${val}`) | ||
} | ||
return val.trim() | ||
@@ -306,5 +320,8 @@ } | ||
} | ||
else if (chr === ' ' && val) { | ||
results.push(val) | ||
val = '' | ||
else if (chr === ' ') { | ||
if (val) { | ||
results.push(val) | ||
val = '' | ||
} | ||
// otherwise ignore the space | ||
} | ||
@@ -318,3 +335,5 @@ else { | ||
if (quoted || escaped) throw new Error('Unexpected line break') | ||
if (quoted || escaped) { | ||
throw new Error(`Unexpected line break at ${results.concat(val).join(' ')}`) | ||
} | ||
results.push(val) | ||
@@ -327,9 +346,12 @@ return results.length > 1 ? results : results[0] | ||
const param = parameter() | ||
return { | ||
const multiple = param.toLowerCase() == 'host' | ||
const result = { | ||
type, | ||
param, | ||
separator: separator(), | ||
value: param.toLowerCase() === 'host' ? patterns() : value() | ||
quoted: !multiple && chr === '"', | ||
value: multiple ? patterns() : value() | ||
} | ||
if (!result.quoted) delete result.quoted | ||
return result | ||
} | ||
@@ -336,0 +358,0 @@ |
{ | ||
"name": "ssh-config", | ||
"description": "SSH config parser and stringifier", | ||
"version": "2.0.0-alpha.1", | ||
"version": "2.0.0-alpha.2", | ||
"author": "Chen Yangjian (https://www.cyj.me)", | ||
@@ -15,3 +15,2 @@ "repository": { | ||
"devDependencies": { | ||
"expect.js": "^0.3.1", | ||
"heredoc": "^1.3.1", | ||
@@ -18,0 +17,0 @@ "mocha": "^5.2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17534
3
346