@@ -19,7 +19,7 @@ import { inject, injectable } from '@theia/core/shared/inversify';
1919import { RemoteSSHConnectionProvider } from '../electron-common/remote-ssh-connection-provider' ;
2020import { AbstractRemoteRegistryContribution , RemoteRegistry } from './remote-registry-contribution' ;
2121import { RemotePreferences } from './remote-preferences' ;
22- import * as SshConfig from 'ssh-config' ;
22+ import SSHConfig , { Directive } from 'ssh-config' ;
2323
2424export namespace RemoteSSHCommands {
2525 export const CONNECT : Command = Command . toLocalizedCommand ( {
@@ -76,11 +76,17 @@ export class RemoteSSHContribution extends AbstractRemoteRegistryContribution {
7676
7777 const wildcardCheck = / [ \? \* \% ] / ;
7878
79- for ( const record of < SshConfig . Section [ ] > sshConfig ) {
80- if ( record . param . toLowerCase ( ) === 'host' && ! wildcardCheck . test ( < string > record . value ) ) {
81- const rec : Record < string , string | string [ ] > = ( < SshConfig . Directive [ ] > record . config ) . reduce (
82- ( pv , item ) => ( { ...pv , [ item . param . toLowerCase ( ) ] : item . value } ) , { 'host' : < string > record . value }
83- ) ;
79+ for ( const record of sshConfig ) {
80+ // check if its a section and if it has a single value
81+ if ( ! ( 'config' in record ) || ! ( typeof record . value === 'string' ) ) {
82+ continue ;
83+ }
84+ if ( record . param . toLowerCase ( ) === 'host' && ! wildcardCheck . test ( record . value ) ) {
85+ const rec : Record < string , string | string [ ] > = ( ( record . config )
86+ . filter ( ( entry ) : entry is Directive => entry . type === SSHConfig . DIRECTIVE ) )
87+ . reduce (
88+ ( pv , item ) => ( { ...pv , [ item . param . toLowerCase ( ) ] : item . value } ) , { 'host' : record . value }
89+ ) ;
8490 const host = ( rec . hostname || rec . host ) + ':' + ( rec . port || '22' ) ;
8591 const user = rec . user || 'root' ;
8692
0 commit comments