ssh-config 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ssh-config.js +21 -8
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ssh-config",
3
3
  "description": "SSH config parser and stringifier",
4
- "version": "5.0.0",
4
+ "version": "5.0.2",
5
5
  "author": "Chen Yangjian (https://www.cyj.me)",
6
6
  "repository": {
7
7
  "type": "git",
package/src/ssh-config.js CHANGED
@@ -20,7 +20,7 @@ var LineType;
20
20
  LineType[LineType["DIRECTIVE"] = 1] = "DIRECTIVE";
21
21
  LineType[LineType["COMMENT"] = 2] = "COMMENT";
22
22
  })(LineType || (exports.LineType = LineType = {}));
23
- const MULTIPLE_VALUE_PROPS = [
23
+ const REPEATABLE_DIRECTIVES = [
24
24
  'IdentityFile',
25
25
  'LocalForward',
26
26
  'RemoteForward',
@@ -115,18 +115,31 @@ class SSHConfig extends Array {
115
115
  };
116
116
  const obj = {};
117
117
  const setProperty = (name, value) => {
118
- if (MULTIPLE_VALUE_PROPS.includes(name)) {
119
- const list = obj[name] || (obj[name] = []);
120
- list.push(value);
118
+ let val;
119
+ if (Array.isArray(value)) {
120
+ if (/ProxyCommand/i.test(name)) {
121
+ val = value.map(({ val, separator }) => `${separator}${val}`).join('').trim();
122
+ }
123
+ else {
124
+ val = value.map(({ val }) => val);
125
+ }
126
+ }
127
+ else {
128
+ val = value;
129
+ }
130
+ const val0 = Array.isArray(val) ? val[0] : val;
131
+ if (REPEATABLE_DIRECTIVES.includes(name)) {
132
+ const list = (obj[name] || (obj[name] = []));
133
+ list.push(...[].concat(val));
121
134
  }
122
135
  else if (obj[name] == null) {
123
136
  if (name === 'HostName') {
124
- context.params.HostName = value;
137
+ context.params.HostName = val0;
125
138
  }
126
139
  else if (name === 'User') {
127
- context.params.User = value;
140
+ context.params.User = val0;
128
141
  }
129
- obj[name] = value;
142
+ obj[name] = val;
130
143
  }
131
144
  };
132
145
  if (opts.User !== undefined) {
@@ -542,7 +555,7 @@ function stringify(config) {
542
555
  if (line.type === LineType.COMMENT) {
543
556
  str += line.content;
544
557
  }
545
- else if (line.type === LineType.DIRECTIVE && MULTIPLE_VALUE_PROPS.includes(line.param)) {
558
+ else if (line.type === LineType.DIRECTIVE && REPEATABLE_DIRECTIVES.includes(line.param)) {
546
559
  (Array.isArray(line.value) ? line.value : [line.value]).forEach((value, i, values) => {
547
560
  str += formatDirective({ ...line, value: typeof value !== 'string' ? value.val : value });
548
561
  if (i < values.length - 1)