diff --git a/src/ssh-config.ts b/src/ssh-config.ts index 5f2f707..fde5b89 100644 --- a/src/ssh-config.ts +++ b/src/ssh-config.ts @@ -185,19 +185,20 @@ export default class SSHConfig extends Array { doFinalPass: false, } - const obj = {} - const setProperty = (name: string, value) => { + const obj: Record = {} + const setProperty = (name: string, value: string | { val: string }[]) => { + const val = Array.isArray(value) ? value.map(({ val }) => val) : value + const val0 = Array.isArray(val) ? val[0] : val if (MULTIPLE_VALUE_PROPS.includes(name)) { - const list = obj[name] || (obj[name] = []) - list.push(value) + const list = (obj[name] || (obj[name] = [])) as string[] + list.push(...([] as string[]).concat(val)) } else if (obj[name] == null) { if (name === 'HostName') { - context.params.HostName = value + context.params.HostName = val0 } else if (name === 'User') { - context.params.User = value + context.params.User = val0 } - - obj[name] = value + obj[name] = val } } diff --git a/test/unit/ssh-config.test.ts b/test/unit/ssh-config.test.ts index 91a3575..1983c02 100644 --- a/test/unit/ssh-config.test.ts +++ b/test/unit/ssh-config.test.ts @@ -40,35 +40,15 @@ describe('SSHConfig', function() { '~/.ssh/id_rsa' ], ProxyCommand: [ - { - 'quoted': false, - 'separator': ' ', - 'val': 'ssh', - }, - { - 'quoted': false, - 'separator': ' ', - 'val': '-q', - }, - { - 'quoted': false, - 'separator': ' ', - 'val': 'gateway', - }, - { - 'quoted': false, - 'separator': ' ', - 'val': '-W', - }, - { - 'quoted': false, - 'separator': ' ', - 'val': '%h:%p', - }, + 'ssh', + '-q', + 'gateway', + '-W', + '%h:%p', ], ServerAliveInterval: '80', User: 'nil', - ForwardAgent: 'true' + ForwardAgent: 'true', }) }) @@ -96,21 +76,9 @@ describe('SSHConfig', function() { for (const host of ['foo', 'foo.bar', 'baz ham']) { assert.deepEqual(config.compute(host), { Host: [ - { - 'quoted': false, - 'separator': ' ', - 'val': 'foo', - }, - { - 'quoted': true, - 'separator': ' ', - 'val': '*.bar', - }, - { - 'quoted': true, - 'separator': ' ', - 'val': 'baz ham', - }, + 'foo', + '*.bar', + 'baz ham', ], HostName: 'example.com', User: 'robb'