Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion src/node_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ ProcessRunner::ProcessRunner(std::shared_ptr<InitializationResultImpl> result,
}

#ifdef _WIN32
if (file_.ends_with("cmd.exe")) {
static constexpr std::string_view cmd_exe = "cmd.exe";
if (file_.size() >= cmd_exe.size() &&
StringEqualNoCaseN(file_.data() + file_.size() - cmd_exe.size(),
cmd_exe.data(),
cmd_exe.size())) {
// If the file is cmd.exe, use the following command line arguments:
// "/c" Carries out the command and exit.
// "/d" Disables execution of AutoRun commands.
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-node-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ describe('node --run [command]', () => {
assert.strictEqual(child.code, 1);
});

it('recognizes cmd.exe case-insensitively', {
skip: !common.isWindows,
}, async () => {
const env = { ...process.env };
const comspecKey = Object.keys(env)
.find((key) => key.toLowerCase() === 'comspec');
assert.notStrictEqual(comspecKey, undefined);
const comspec = env[comspecKey];
assert.match(comspec, /cmd\.exe$/i);
delete env[comspecKey];
env.ComSpec = comspec.replace(/cmd\.exe$/i, 'CMD.EXE');

const child = await common.spawnPromisified(
process.execPath,
[ '--run', 'pwd-windows'],
{ cwd: fixtures.path('run-script'), env },
);
assert.strictEqual(child.stdout.trim(), fixtures.path('run-script'));
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});

it('adds node_modules/.bin to path', async () => {
const child = await common.spawnPromisified(
process.execPath,
Expand Down
Loading