Skip to content

Commit 11266c2

Browse files
committed
src: match cmd.exe case-insensitively in task runner
Use a case-insensitive suffix comparison for ComSpec so uppercase and mixed-case CMD.EXE paths use the correct /c invocation. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
1 parent a4aa3c0 commit 11266c2

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/node_task_runner.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ ProcessRunner::ProcessRunner(std::shared_ptr<InitializationResultImpl> result,
6060
}
6161

6262
#ifdef _WIN32
63-
if (file_.ends_with("cmd.exe")) {
63+
static constexpr std::string_view cmd_exe = "cmd.exe";
64+
if (file_.size() >= cmd_exe.size() &&
65+
StringEqualNoCaseN(file_.data() + file_.size() - cmd_exe.size(),
66+
cmd_exe.data(),
67+
cmd_exe.size())) {
6468
// If the file is cmd.exe, use the following command line arguments:
6569
// "/c" Carries out the command and exit.
6670
// "/d" Disables execution of AutoRun commands.

test/parallel/test-node-run.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ describe('node --run [command]', () => {
3434
assert.strictEqual(child.code, 1);
3535
});
3636

37+
it('recognizes cmd.exe case-insensitively', {
38+
skip: !common.isWindows,
39+
}, async () => {
40+
const env = { ...process.env };
41+
const comspecKey = Object.keys(env)
42+
.find((key) => key.toLowerCase() === 'comspec');
43+
assert.notStrictEqual(comspecKey, undefined);
44+
const comspec = env[comspecKey];
45+
assert.match(comspec, /cmd\.exe$/i);
46+
delete env[comspecKey];
47+
env.ComSpec = comspec.replace(/cmd\.exe$/i, 'CMD.EXE');
48+
49+
const child = await common.spawnPromisified(
50+
process.execPath,
51+
[ '--run', 'pwd-windows'],
52+
{ cwd: fixtures.path('run-script'), env },
53+
);
54+
assert.strictEqual(child.stdout.trim(), fixtures.path('run-script'));
55+
assert.strictEqual(child.stderr, '');
56+
assert.strictEqual(child.code, 0);
57+
});
58+
3759
it('adds node_modules/.bin to path', async () => {
3860
const child = await common.spawnPromisified(
3961
process.execPath,

0 commit comments

Comments
 (0)