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>
PR-URL: https://github.com/nodejs/node/pull/64907
Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
Archkon authored and Antoine du Hamel committed 2026-08-26 00:55:40 +02:00
1 parent ad7c67026b
commit d8a0f288ab
2 files changed
+27 -1

No files matched your search

+5 -1
View File
@@ -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.
+22
View File
@@ -37,6 +37,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,