Skip to content

Commit

Permalink
fix: trailing comments, to be or not to be? (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjake authored Apr 9, 2024
1 parent 4c356c5 commit 2a134ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
2 changes: 1 addition & 1 deletion src/ssh-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion test/unit/parse.test.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
})
})

0 comments on commit 2a134ab

Please sign in to comment.