From 11266c2bf5331e2cb220156adf201674b45b510b Mon Sep 17 00:00:00 2001 From: Archkon <180910180+Archkon@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:39:31 +0800 Subject: [PATCH] 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> --- src/node_task_runner.cc | 6 +++++- test/parallel/test-node-run.js | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/node_task_runner.cc b/src/node_task_runner.cc index 22c02e83e12e..edd3d3625e4c 100644 --- a/src/node_task_runner.cc +++ b/src/node_task_runner.cc @@ -60,7 +60,11 @@ ProcessRunner::ProcessRunner(std::shared_ptr 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. diff --git a/test/parallel/test-node-run.js b/test/parallel/test-node-run.js index e24117f6b165..6b72da7f2e4f 100644 --- a/test/parallel/test-node-run.js +++ b/test/parallel/test-node-run.js @@ -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,