Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd70a586

Browse files
authored
fix: specify--header-command when runningcoder start (#526)
1 parent73f866d commitd70a586

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

‎CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
##Unreleased
44

5+
###Fixed
6+
7+
- Use`--header-command` properly when starting a workspace.
8+
59
##[v1.9.1](https://github.com/coder/vscode-coder/releases/tag/v1.9.1) 2025-05-27
610

711
###Fixed

‎src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as vscode from "vscode"
99
import*aswsfrom"ws"
1010
import{errToStr}from"./api-helper"
1111
import{CertificateError}from"./error"
12+
import{getHeaderArgs}from"./headers"
1213
import{getProxyForUrl}from"./proxy"
1314
import{Storage}from"./storage"
1415
import{expandPath}from"./util"
@@ -168,6 +169,7 @@ export async function startWorkspaceIfStoppedOrFailed(
168169
conststartArgs=[
169170
"--global-config",
170171
globalConfigDir,
172+
...getHeaderArgs(vscode.workspace.getConfiguration()),
171173
"start",
172174
"--yes",
173175
workspace.owner_name+"/"+workspace.name,

‎src/headers.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import*ascpfrom"child_process"
2+
import*asosfrom"os"
23
import*asutilfrom"util"
3-
4-
import{WorkspaceConfiguration}from"vscode"
4+
importtype{WorkspaceConfiguration}from"vscode"
5+
import{escapeCommandArg}from"./util"
56

67
exportinterfaceLogger{
78
writeToCoderOutputChannel(message:string):void
@@ -25,6 +26,23 @@ export function getHeaderCommand(config: WorkspaceConfiguration): string | undef
2526
returncmd
2627
}
2728

29+
exportfunctiongetHeaderArgs(config:WorkspaceConfiguration):string[]{
30+
// Escape a command line to be executed by the Coder binary, so ssh doesn't substitute variables.
31+
constescapeSubcommand:(str:string)=>string=
32+
os.platform()==="win32"
33+
?// On Windows variables are %VAR%, and we need to use double quotes.
34+
(str)=>escapeCommandArg(str).replace(/%/g,"%%")
35+
:// On *nix we can use single quotes to escape $VARS.
36+
// Note single quotes cannot be escaped inside single quotes.
37+
(str)=>`'${str.replace(/'/g,"'\\''")}'`
38+
39+
constcommand=getHeaderCommand(config)
40+
if(!command){
41+
return[]
42+
}
43+
return["--header-command",escapeSubcommand(command)]
44+
}
45+
2846
// TODO: getHeaders might make more sense to directly implement on Storage
2947
// but it is difficult to test Storage right now since we use vitest instead of
3048
// the standard extension testing framework which would give us access to vscode

‎src/remote.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import { extractAgents } from "./api-helper"
1414
import*asclifrom"./cliManager"
1515
import{Commands}from"./commands"
1616
import{featureSetForVersion,FeatureSet}from"./featureSet"
17-
import{getHeaderCommand}from"./headers"
17+
import{getHeaderArgs}from"./headers"
1818
import{Inbox}from"./inbox"
1919
import{SSHConfig,SSHValues,mergeSSHConfigValues}from"./sshConfig"
2020
import{computeSSHProperties,sshSupportsSetEnv}from"./sshSupport"
2121
import{Storage}from"./storage"
22-
import{AuthorityPrefix,expandPath,findPort,parseRemoteAuthority}from"./util"
22+
import{AuthorityPrefix,escapeCommandArg,expandPath,findPort,parseRemoteAuthority}from"./util"
2323
import{WorkspaceMonitor}from"./workspaceMonitor"
2424

2525
exportinterfaceRemoteDetailsextendsvscode.Disposable{
@@ -611,32 +611,18 @@ export class Remote {
611611
constsshConfig=newSSHConfig(sshConfigFile)
612612
awaitsshConfig.load()
613613

614-
constescape=(str:string):string=>`"${str.replace(/"/g,'\\"')}"`
615-
// Escape a command line to be executed by the Coder binary, so ssh doesn't substitute variables.
616-
constescapeSubcommand:(str:string)=>string=
617-
os.platform()==="win32"
618-
?// On Windows variables are %VAR%, and we need to use double quotes.
619-
(str)=>escape(str).replace(/%/g,"%%")
620-
:// On *nix we can use single quotes to escape $VARS.
621-
// Note single quotes cannot be escaped inside single quotes.
622-
(str)=>`'${str.replace(/'/g,"'\\''")}'`
623-
624-
// Add headers from the header command.
625-
letheaderArg=""
626-
constheaderCommand=getHeaderCommand(vscode.workspace.getConfiguration())
627-
if(typeofheaderCommand==="string"&&headerCommand.trim().length>0){
628-
headerArg=` --header-command${escapeSubcommand(headerCommand)}`
629-
}
614+
constheaderArgs=getHeaderArgs(vscode.workspace.getConfiguration())
615+
constheaderArgList=headerArgs.length>0 ?`${headerArgs.join(" ")}` :""
630616

631617
consthostPrefix=label ?`${AuthorityPrefix}.${label}--` :`${AuthorityPrefix}--`
632618

633619
constproxyCommand=featureSet.wildcardSSH
634-
?`${escape(binaryPath)}${headerArg} --global-config${escape(
620+
?`${escapeCommandArg(binaryPath)}${headerArgList} --global-config${escapeCommandArg(
635621
path.dirname(this.storage.getSessionTokenPath(label)),
636-
)} ssh --stdio --usage-app=vscode --disable-autostart --network-info-dir${escape(this.storage.getNetworkInfoPath())}${awaitthis.formatLogArg(logDir)} --ssh-host-prefix${hostPrefix} %h`
637-
:`${escape(binaryPath)}${headerArg} vscodessh --network-info-dir${escape(
622+
)} ssh --stdio --usage-app=vscode --disable-autostart --network-info-dir${escapeCommandArg(this.storage.getNetworkInfoPath())}${awaitthis.formatLogArg(logDir)} --ssh-host-prefix${hostPrefix} %h`
623+
:`${escapeCommandArg(binaryPath)}${headerArgList} vscodessh --network-info-dir${escapeCommandArg(
638624
this.storage.getNetworkInfoPath(),
639-
)}${awaitthis.formatLogArg(logDir)} --session-token-file${escape(this.storage.getSessionTokenPath(label))} --url-file${escape(
625+
)}${awaitthis.formatLogArg(logDir)} --session-token-file${escapeCommandArg(this.storage.getSessionTokenPath(label))} --url-file${escapeCommandArg(
640626
this.storage.getUrlPath(label),
641627
)} %h`
642628

‎src/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,7 @@ export function countSubstring(needle: string, haystack: string): number {
136136
}
137137
returncount
138138
}
139+
140+
exportfunctionescapeCommandArg(arg:string):string{
141+
return`"${arg.replace(/"/g,'\\"')}"`
142+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp