ssh-config 4.4.2 → 4.4.4

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 +5 -3
  2. package/src/ssh-config.js +17 -9
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": "4.4.2",
4
+ "version": "4.4.4",
5
5
  "author": "Chen Yangjian (https://www.cyj.me)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,13 +16,15 @@
16
16
  "devDependencies": {
17
17
  "@types/mocha": "^9.1.0",
18
18
  "@types/node": "^17.0.45",
19
+ "@types/sinon": "^17.0.3",
19
20
  "@typescript-eslint/eslint-plugin": "^5.48.0",
20
21
  "@typescript-eslint/parser": "^5.48.0",
21
22
  "eslint": "^8.31.0",
22
23
  "heredoc": "^1.3.1",
23
24
  "mocha": "^8.2.1",
24
25
  "nyc": "^15.1.0",
25
- "typescript": "^4.6.3"
26
+ "sinon": "^17.0.1",
27
+ "typescript": "^5.4.4"
26
28
  },
27
29
  "scripts": {
28
30
  "lint": "eslint --ext ts .",
@@ -33,7 +35,7 @@
33
35
  "test:coverage": "nyc mocha --exit --recursive && nyc report --reporter=lcov"
34
36
  },
35
37
  "engine": {
36
- "node": ">= 10.0.0"
38
+ "node": ">= 14.0.0"
37
39
  },
38
40
  "license": "MIT"
39
41
  }
package/src/ssh-config.js CHANGED
@@ -17,7 +17,7 @@ var LineType;
17
17
  (function (LineType) {
18
18
  LineType[LineType["DIRECTIVE"] = 1] = "DIRECTIVE";
19
19
  LineType[LineType["COMMENT"] = 2] = "COMMENT";
20
- })(LineType = exports.LineType || (exports.LineType = {}));
20
+ })(LineType || (exports.LineType = LineType = {}));
21
21
  const MULTIPLE_VALUE_PROPS = [
22
22
  'IdentityFile',
23
23
  'LocalForward',
@@ -91,13 +91,21 @@ class SSHConfig extends Array {
91
91
  compute(opts) {
92
92
  if (typeof opts === 'string')
93
93
  opts = { Host: opts };
94
+ let userInfo;
95
+ try {
96
+ userInfo = os_1.default.userInfo();
97
+ }
98
+ catch (_a) {
99
+ // os.userInfo() throws a SystemError if a user has no username or homedir.
100
+ userInfo = { username: process.env.USER || process.env.USERNAME || '' };
101
+ }
94
102
  const context = {
95
103
  params: {
96
104
  Host: opts.Host,
97
105
  HostName: opts.Host,
98
106
  OriginalHost: opts.Host,
99
- User: os_1.default.userInfo().username,
100
- LocalUser: os_1.default.userInfo().username,
107
+ User: userInfo.username,
108
+ LocalUser: userInfo.username,
101
109
  },
102
110
  inFinalPass: false,
103
111
  doFinalPass: false,
@@ -140,11 +148,11 @@ class SSHConfig extends Array {
140
148
  }
141
149
  }
142
150
  }
143
- if (canonicalDomains.length > 0 && canonicalizeHostName) {
151
+ if (canonicalDomains.length > 0 && canonicalizeHostName && context.params.Host === context.params.OriginalHost) {
144
152
  for (const domain of canonicalDomains) {
145
- const host = `${line.value}.${domain}`;
146
- const { stdout } = (0, child_process_1.spawnSync)('nslookup', [host]);
147
- if (!/server can't find/.test(stdout.toString())) {
153
+ const host = `${context.params.OriginalHost}.${domain}`;
154
+ const { status, stderr } = (0, child_process_1.spawnSync)('nslookup', [host]);
155
+ if (status === 0 && !/can't find/.test(stderr.toString())) {
148
156
  context.params.Host = host;
149
157
  setProperty('Host', host);
150
158
  doPass();
@@ -294,9 +302,9 @@ class SSHConfig extends Array {
294
302
  return config;
295
303
  }
296
304
  }
297
- exports.default = SSHConfig;
298
305
  SSHConfig.DIRECTIVE = LineType.DIRECTIVE;
299
306
  SSHConfig.COMMENT = LineType.COMMENT;
307
+ exports.default = SSHConfig;
300
308
  /**
301
309
  * Parse SSH config text into structured object.
302
310
  */
@@ -408,7 +416,7 @@ function parse(text) {
408
416
  }
409
417
  // otherwise ignore the space
410
418
  }
411
- else if (chr === '#') {
419
+ else if (chr === '#' && results.length > 0) {
412
420
  break;
413
421
  }
414
422
  else {