diff --git a/History.md b/History.md index 7c83160..727e548 100644 --- a/History.md +++ b/History.md @@ -1,7 +1,13 @@ +4.0.4 / 2020-09-01 +================== + + * fix: should not quote directives like LocalForward (#38) + + 4.0.3 / 2020-08-24 ================== - * fix: quote values that contain white spaces + * fix: quote values that contain white spaces (36) 4.0.2 / 2020-02-09 diff --git a/index.js b/index.js index 54bdddc..906b084 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const RE_SPACE = /\s/ const RE_LINE_BREAK = /\r|\n/ const RE_SECTION_DIRECTIVE = /^(Host|Match)$/i const RE_MULTI_VALUE_DIRECTIVE = /^(GlobalKnownHostsFile|Host|IPQoS|SendEnv|UserKnownHostsFile)$/i +const RE_QUOTE_DIRECTIVE = /^(?:CertificateFile|IdentifyFile|User)$/i const DIRECTIVE = 1 const COMMENT = 2 @@ -172,7 +173,7 @@ class SSHConfig extends Array { } else if (line.type === DIRECTIVE) { const quoted = line.quoted - || (!/Command$/i.test(line.param) && RE_SPACE.test(line.value)) + || (RE_QUOTE_DIRECTIVE.test(line.param) && RE_SPACE.test(line.value)) const value = formatValue(line.value, quoted) str += `${line.param}${line.separator}${value}` } diff --git a/package.json b/package.json index c91d7d6..cec5c69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ssh-config", "description": "SSH config parser and stringifier", - "version": "4.0.3", + "version": "4.0.4", "author": "Chen Yangjian (https://www.cyj.me)", "repository": { "type": "git", diff --git a/test/test.stringify.js b/test/test.stringify.js index b7999d3..a0453c9 100644 --- a/test/test.stringify.js +++ b/test/test.stringify.js @@ -80,4 +80,17 @@ describe('stringify', function() { User "dan abramov" */})) }) + + // #38 + it('.stringify LocalForward without quotes', function() { + const config = parse(heredoc(function() {/* + Host example + LocalForward 1234 localhost:1234 + */})) + + assert.equal(stringify(config), heredoc(function() {/* + Host example + LocalForward 1234 localhost:1234 + */})) + }) })