Skip to content

Commit

Permalink
Simplify Windows-related code
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 8, 2024
1 parent 742a917 commit 258a583
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions source/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ export const spawnSubprocess = async (file, commandArguments, options, context)
? [process.execPath, [...process.execArgv.filter(flag => !flag.startsWith('--inspect')), ...commandArguments]]
: [file, commandArguments];

const forcedShell = await getForcedShell(file, options);
const instance = spawn(...escapeArguments(file, commandArguments, forcedShell), {
...options,
shell: options.shell || forcedShell,
});
const instance = spawn(...escapeArguments(file, commandArguments, options, await getForcedShell(file, options)));
bufferOutput(instance.stdout, context, 'stdout');
bufferOutput(instance.stderr, context, 'stderr');

Expand Down
6 changes: 3 additions & 3 deletions source/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ const exeExtensions = ['.exe', '.com'];

// When setting `shell: true` under-the-hood, we must manually escape the file and arguments.
// This ensures arguments are properly split, and prevents command injection.
export const escapeArguments = (file, commandArguments, forcedShell) => forcedShell
? [escapeFile(file), commandArguments.map(argument => escapeArgument(argument))]
: [file, commandArguments];
export const escapeArguments = (file, commandArguments, options, forcedShell) => forcedShell
? [escapeFile(file), commandArguments.map(argument => escapeArgument(argument)), {...options, shell: true}]
: [file, commandArguments, options];

// `cmd.exe` escaping for arguments.
// Taken from https://github.com/moxystudio/node-cross-spawn
Expand Down

0 comments on commit 258a583

Please sign in to comment.