Skip to content

Commit d9e651a

Browse files
committed
Trim headerCommand and defaultUrl settings and their env variables
1 parent e5b7060 commit d9e651a

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/commands.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ export class Commands {
102102
* CODER_URL or enter a new one. Undefined means the user aborted.
103103
*/
104104
private async askURL(selection?: string): Promise<string | undefined> {
105-
const defaultURL =
106-
vscode.workspace.getConfiguration().get<string>("coder.defaultUrl") ?? "";
105+
const defaultURL = vscode.workspace
106+
.getConfiguration()
107+
.get<string>("coder.defaultUrl")
108+
?.trim();
107109
const quickPick = vscode.window.createQuickPick();
108-
quickPick.value = selection || defaultURL || process.env.CODER_URL || "";
110+
quickPick.value =
111+
selection || defaultURL || process.env.CODER_URL?.trim() || "";
109112
quickPick.placeholder = "https://example.coder.com";
110113
quickPick.title = "Enter the URL of your Coder deployment.";
111114

src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
423423
// Handle autologin, if not already logged in.
424424
const cfg = vscode.workspace.getConfiguration();
425425
if (cfg.get("coder.autologin") === true) {
426-
const defaultUrl = cfg.get("coder.defaultUrl") || process.env.CODER_URL;
426+
const defaultUrl =
427+
cfg.get<string>("coder.defaultUrl")?.trim() ||
428+
process.env.CODER_URL?.trim();
427429
if (defaultUrl) {
428430
vscode.commands.executeCommand(
429431
"coder.login",

src/headers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ describe("getHeaderCommand", () => {
123123
expect(getHeaderCommand(config)).toBeUndefined();
124124
});
125125

126-
it("should return undefined if coder.headerCommand is not a string", () => {
126+
it("should return undefined if coder.headerCommand is a blank string", () => {
127127
const config = {
128-
get: () => 1234,
128+
get: () => " ",
129129
} as unknown as WorkspaceConfiguration;
130130

131131
expect(getHeaderCommand(config)).toBeUndefined();

src/headers.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ export function getHeaderCommand(
1919
config: WorkspaceConfiguration,
2020
): string | undefined {
2121
const cmd =
22-
config.get("coder.headerCommand") || process.env.CODER_HEADER_COMMAND;
23-
if (!cmd || typeof cmd !== "string") {
24-
return undefined;
25-
}
26-
return cmd;
22+
config.get<string>("coder.headerCommand")?.trim() ||
23+
process.env.CODER_HEADER_COMMAND?.trim();
24+
25+
return cmd ? cmd : undefined;
2726
}
2827

2928
export function getHeaderArgs(config: WorkspaceConfiguration): string[] {

0 commit comments

Comments
 (0)