Skip to content

Commit

Permalink
fix: enable quoting for specific directives (#39)
Browse files Browse the repository at this point in the history
fixes #38
  • Loading branch information
cyjake authored Sep 1, 2020
1 parent d23d44c commit 0e8efc4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
8 changes: 7 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 13 additions & 0 deletions test/test.stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/}))
})
})

0 comments on commit 0e8efc4

Please sign in to comment.