ssh-config 4.4.1 → 4.4.3

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 +4 -2
  2. package/src/ssh-config.js +17 -3
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.1",
4
+ "version": "4.4.3",
5
5
  "author": "Chen Yangjian (https://www.cyj.me)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,12 +16,14 @@
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",
26
+ "sinon": "^17.0.1",
25
27
  "typescript": "^4.6.3"
26
28
  },
27
29
  "scripts": {
@@ -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
@@ -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,
@@ -357,6 +365,9 @@ function parse(text) {
357
365
  else if (chr === '\\') {
358
366
  escaped = true;
359
367
  }
368
+ else if (chr === '#' && !quoted) {
369
+ break;
370
+ }
360
371
  else {
361
372
  val += chr;
362
373
  }
@@ -398,13 +409,16 @@ function parse(text) {
398
409
  else if (quoted) {
399
410
  val += chr;
400
411
  }
401
- else if (/[ \t]/.test(chr)) {
412
+ else if (/[ \t=]/.test(chr)) {
402
413
  if (val) {
403
414
  results.push(val);
404
415
  val = '';
405
416
  }
406
417
  // otherwise ignore the space
407
418
  }
419
+ else if (chr === '#') {
420
+ break;
421
+ }
408
422
  else {
409
423
  val += chr;
410
424
  }