|
1 | 1 | import { isKeyringSupported } from "../core/cliCredentialManager"; |
2 | | -import { escapeCommandArg } from "../util"; |
| 2 | +import { escapeCommandArg, escapeShellArg } from "../util"; |
3 | 3 |
|
4 | 4 | import { getHeaderArgs } from "./headers"; |
5 | 5 |
|
@@ -29,41 +29,38 @@ export function getUserGlobalFlags( |
29 | 29 | ); |
30 | 30 | } |
31 | 31 |
|
32 | | -/** |
33 | | - * Returns global configuration flags for Coder CLI commands with auth values |
34 | | - * escaped for shell use (e.g., `terminal.sendText`, `spawn({ shell: true })`). |
35 | | - */ |
| 32 | +/** Flags for shell contexts (`terminal.sendText`, `spawn({ shell: true })`). */ |
36 | 33 | export function getGlobalShellFlags( |
37 | 34 | configs: Pick<WorkspaceConfiguration, "get">, |
38 | 35 | auth: CliAuth, |
39 | 36 | ): string[] { |
40 | | - return buildGlobalFlags(configs, auth, escapeCommandArg); |
| 37 | + return buildGlobalFlags(configs, auth, escapeCommandArg, escapeShellArg); |
41 | 38 | } |
42 | 39 |
|
43 | | -/** |
44 | | - * Returns global configuration flags for Coder CLI commands with raw auth |
45 | | - * values suitable for `execFile` (no shell escaping). |
46 | | - */ |
| 40 | +/** Raw flags for `execFile` or `spawn` without a shell. */ |
47 | 41 | export function getGlobalFlags( |
48 | 42 | configs: Pick<WorkspaceConfiguration, "get">, |
49 | 43 | auth: CliAuth, |
50 | 44 | ): string[] { |
51 | | - return buildGlobalFlags(configs, auth, (s) => s); |
| 45 | + return buildGlobalFlags(configs, auth, identity, identity); |
52 | 46 | } |
53 | 47 |
|
| 48 | +const identity = (s: string) => s; |
| 49 | + |
54 | 50 | function buildGlobalFlags( |
55 | 51 | configs: Pick<WorkspaceConfiguration, "get">, |
56 | 52 | auth: CliAuth, |
57 | | - esc: (s: string) => string, |
| 53 | + escAuth: (s: string) => string, |
| 54 | + escHeader: (s: string) => string, |
58 | 55 | ): string[] { |
59 | 56 | const authFlags = |
60 | 57 | auth.mode === "url" |
61 | | - ? ["--url", esc(auth.url)] |
62 | | - : ["--global-config", esc(auth.configDir)]; |
| 58 | + ? ["--url", escAuth(auth.url)] |
| 59 | + : ["--global-config", escAuth(auth.configDir)]; |
63 | 60 |
|
64 | 61 | const filtered = stripManagedFlags(getUserGlobalFlags(configs)); |
65 | 62 |
|
66 | | - return [...filtered, ...authFlags, ...getHeaderArgs(configs)]; |
| 63 | + return [...filtered, ...authFlags, ...getHeaderArgs(configs, escHeader)]; |
67 | 64 | } |
68 | 65 |
|
69 | 66 | function stripManagedFlags(flags: string[]): string[] { |
|
0 commit comments