@@ -20,13 +20,14 @@ import { extractAgents } from "./api-helper";
2020import * as cli from "./cliManager" ;
2121import { Commands } from "./commands" ;
2222import { featureSetForVersion , FeatureSet } from "./featureSet" ;
23- import { getHeaderCommand } from "./headers" ;
23+ import { getHeaderArgs } from "./headers" ;
2424import { Inbox } from "./inbox" ;
2525import { SSHConfig , SSHValues , mergeSSHConfigValues } from "./sshConfig" ;
2626import { computeSSHProperties , sshSupportsSetEnv } from "./sshSupport" ;
2727import { Storage } from "./storage" ;
2828import {
2929 AuthorityPrefix ,
30+ escapeCommandArg ,
3031 expandPath ,
3132 findPort ,
3233 parseRemoteAuthority ,
@@ -758,34 +759,21 @@ export class Remote {
758759 const sshConfig = new SSHConfig ( sshConfigFile ) ;
759760 await sshConfig . load ( ) ;
760761
761- const escape = ( str : string ) : string => `"${ str . replace ( / " / g, '\\"' ) } "` ;
762- // Escape a command line to be executed by the Coder binary, so ssh doesn't substitute variables.
763- const escapeSubcommand : ( str : string ) => string =
764- os . platform ( ) === "win32"
765- ? // On Windows variables are %VAR%, and we need to use double quotes.
766- ( str ) => escape ( str ) . replace ( / % / g, "%%" )
767- : // On *nix we can use single quotes to escape $VARS.
768- // Note single quotes cannot be escaped inside single quotes.
769- ( str ) => `'${ str . replace ( / ' / g, "'\\''" ) } '` ;
770-
771- // Add headers from the header command.
772- let headerArg = "" ;
773- const headerCommand = getHeaderCommand ( vscode . workspace . getConfiguration ( ) ) ;
774- if ( typeof headerCommand === "string" && headerCommand . trim ( ) . length > 0 ) {
775- headerArg = ` --header-command ${ escapeSubcommand ( headerCommand ) } ` ;
776- }
762+ const headerArgs = getHeaderArgs ( vscode . workspace . getConfiguration ( ) ) ;
763+ const headerArgList =
764+ headerArgs . length > 0 ? ` ${ headerArgs . join ( " " ) } ` : "" ;
777765
778766 const hostPrefix = label
779767 ? `${ AuthorityPrefix } .${ label } --`
780768 : `${ AuthorityPrefix } --` ;
781769
782770 const proxyCommand = featureSet . wildcardSSH
783- ? `${ escape ( binaryPath ) } ${ headerArg } --global-config ${ escape (
771+ ? `${ escapeCommandArg ( binaryPath ) } ${ headerArgList } --global-config ${ escapeCommandArg (
784772 path . dirname ( this . storage . getSessionTokenPath ( label ) ) ,
785- ) } ssh --stdio --usage-app=vscode --disable-autostart --network-info-dir ${ escape ( this . storage . getNetworkInfoPath ( ) ) } ${ await this . formatLogArg ( logDir ) } --ssh-host-prefix ${ hostPrefix } %h`
786- : `${ escape ( binaryPath ) } ${ headerArg } vscodessh --network-info-dir ${ escape (
773+ ) } ssh --stdio --usage-app=vscode --disable-autostart --network-info-dir ${ escapeCommandArg ( this . storage . getNetworkInfoPath ( ) ) } ${ await this . formatLogArg ( logDir ) } --ssh-host-prefix ${ hostPrefix } %h`
774+ : `${ escapeCommandArg ( binaryPath ) } ${ headerArgList } vscodessh --network-info-dir ${ escapeCommandArg (
787775 this . storage . getNetworkInfoPath ( ) ,
788- ) } ${ await this . formatLogArg ( logDir ) } --session-token-file ${ escape ( this . storage . getSessionTokenPath ( label ) ) } --url-file ${ escape (
776+ ) } ${ await this . formatLogArg ( logDir ) } --session-token-file ${ escapeCommandArg ( this . storage . getSessionTokenPath ( label ) ) } --url-file ${ escapeCommandArg (
789777 this . storage . getUrlPath ( label ) ,
790778 ) } %h`;
791779
0 commit comments