Skip to content

execSync -> execFileSync for RescriptEditorSupport binary invocation #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions server/src/RescriptEditorSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from "url";
import { RequestMessage } from "vscode-languageserver";
import * as utils from "./utils";
import * as path from "path";
import { execSync } from "child_process";
import { execFileSync } from "child_process";
import fs from "fs";

let binaryPath = path.join(
Expand All @@ -20,7 +20,7 @@ let findExecutable = (uri: string) => {
return null;
} else {
return {
binaryPathQuoted: '"' + binaryPath + '"', // path could have white space
binaryPath: binaryPath,
filePathQuoted: '"' + filePath + '"',
cwd: projectRootPath,
};
Expand All @@ -38,16 +38,16 @@ export function runDumpCommand(msg: RequestMessage): dumpCommandResult | null {
}

let command =
executable.binaryPathQuoted +
" dump " +
executable.filePathQuoted +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument should not be quoted anymore now that an array of arguments is passed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm modifying the binary right now. execFileSync's arguments array's each item is considered as a space-separated command. Currently this still needs quoting since we concatenate the file path with the 2 position arguments. If we want to leverage proper escaping from execFileSync, we need to stop concatenating too. Aka the binary's position arguments shouldn't be passed as filePath:line:col but filePath line col.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, you're right. This... works. We'll revisit the binary's path:line:col argument parsing later. Less parsing = less error

":" +
msg.params.position.line +
":" +
msg.params.position.character;

try {
let stdout = execSync(command, { cwd: executable.cwd });
let stdout = execFileSync(executable.binaryPath, ["dump", command], {
cwd: executable.cwd,
});
let parsed = JSON.parse(stdout.toString());
if (parsed && parsed[0]) {
return parsed[0];
Expand All @@ -73,18 +73,18 @@ export function runCompletionCommand(
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });

let command =
executable.binaryPathQuoted +
" complete " +
executable.filePathQuoted +
":" +
msg.params.position.line +
":" +
msg.params.position.character +
" " +
tmpname;
msg.params.position.character;

try {
let stdout = execSync(command, { cwd: executable.cwd });
let stdout = execFileSync(
executable.binaryPath,
["complete", command, tmpname],
{ cwd: executable.cwd }
);
let parsed = JSON.parse(stdout.toString());
if (parsed && parsed[0]) {
return parsed;
Expand Down