Skip to content

Commit b319b62

Browse files
authored
fix bug for path containing whitespaces (#35)
1 parent d928c06 commit b319b62

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/commands/show.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function showProblemInternal(channel: vscode.OutputChannel, id: string): P
4949

5050
const outdir: string = await selectWorkspaceFolder();
5151
await fse.ensureDir(outdir);
52-
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "show", id, "-gx", "-l", language, "-o", outdir]);
52+
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "show", id, "-gx", "-l", language, "-o", `"${outdir}"`]);
5353
const reg: RegExp = /\* Source Code:\s*(.*)/;
5454
const match: RegExpMatchArray | null = result.match(reg);
5555
if (match && match.length >= 2) {

src/commands/submit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function submitSolution(channel: vscode.OutputChannel, uri?: vscode
1919
}
2020

2121
try {
22-
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "submit", filePath]);
22+
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "submit", `"${filePath}"`]);
2323
await showResultFile(result);
2424
} catch (error) {
2525
await promptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.", DialogType.error, channel);

src/commands/test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U
4747
let result: string | undefined;
4848
switch (choice.value) {
4949
case ":default":
50-
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", filePath]);
50+
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`]);
5151
break;
5252
case ":direct":
5353
const testString: string | undefined = await vscode.window.showInputBox({
@@ -57,15 +57,15 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U
5757
ignoreFocusOut: true,
5858
});
5959
if (testString) {
60-
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", filePath, "-t", `"${testString.replace(/"/g, "")}"`]);
60+
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`, "-t", `"${testString.replace(/"/g, "")}"`]);
6161
}
6262
break;
6363
case ":file":
6464
const testFile: vscode.Uri[] | undefined = await showFileSelectDialog();
6565
if (testFile && testFile.length) {
6666
const input: string = await fse.readFile(testFile[0].fsPath, "utf-8");
6767
if (input.trim()) {
68-
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", filePath, "-t", `"${input.replace(/"/g, "").replace(/\r?\n/g, "\\n")}"`]);
68+
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`, "-t", `"${input.replace(/"/g, "").replace(/\r?\n/g, "\\n")}"`]);
6969
} else {
7070
vscode.window.showErrorMessage("The selected test file must not be empty.");
7171
}

src/leetCodeManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
4343
try {
4444
const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise<void> => {
4545
let result: string = "";
46-
const childProc: cp.ChildProcess = cp.spawn("node", [leetCodeBinaryPath, "user", "-l"]);
46+
const childProc: cp.ChildProcess = cp.spawn("node", [leetCodeBinaryPath, "user", "-l"], { shell: true });
4747
childProc.stdout.on("data", (data: string | Buffer) => {
4848
data = data.toString();
4949
result = result.concat(data);

src/shared.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as path from "path";
44
import * as vscode from "vscode";
55

6-
export const leetCodeBinaryPath: string = path.join(__dirname, "..", "..", "node_modules", "leetcode-cli", "bin", "leetcode");
6+
export const leetCodeBinaryPath: string = `"${path.join(__dirname, "..", "..", "node_modules", "leetcode-cli", "bin", "leetcode")}"`;
77

88
export interface IQuickItemEx<T> extends vscode.QuickPickItem {
99
value: T;

0 commit comments

Comments
 (0)