diff --git a/package.json b/package.json index bad68c4..27bd572 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "mocha": "^8.2.1", "nyc": "^15.1.0", "sinon": "^17.0.1", - "typescript": "^4.6.3" + "typescript": "^5.4.4" }, "scripts": { "lint": "eslint --ext ts .", diff --git a/src/ssh-config.ts b/src/ssh-config.ts index c94fbb3..436f11a 100644 --- a/src/ssh-config.ts +++ b/src/ssh-config.ts @@ -556,7 +556,7 @@ export function parse(text: string): SSHConfig { } // otherwise ignore the space } - else if (chr === '#') { + else if (chr === '#' && results.length > 0) { break } else { diff --git a/test/unit/parse.test.ts b/test/unit/parse.test.ts index fa9f29e..c1cbfbe 100644 --- a/test/unit/parse.test.ts +++ b/test/unit/parse.test.ts @@ -1,7 +1,7 @@ import { strict as assert } from 'assert' import fs from 'fs' import path from 'path' -import SSHConfig from '../..' +import SSHConfig, { LineType } from '../..' const { parse, COMMENT, DIRECTIVE } = SSHConfig @@ -299,6 +299,7 @@ describe('parse', function() { }) }) + // https://github.com/cyjake/ssh-config/issues/73 it('.parse match with comments', function() { const config = parse(` # CLOUDFLARE SETUP https://URL_REDACTED @@ -334,4 +335,15 @@ describe('parse', function() { host: '*.ligo-*.caltech.edu', }) }) + + // https://github.com/cyjake/ssh-config/issues/79 + it('.parse with # within value', () => { + const config = parse(` + Host name#with#hash + HostName localhost + `) + assert.equal(config.length, 1) + assert.equal(config[0].type, LineType.DIRECTIVE) + assert.equal(config[0].value, 'name#with#hash') + }) })