FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

src: match cmd.exe case-insensitively in task runner · nodejs/node@d8a0f28 · GitHub

/ node Public

Commit d8a0f28

Browse files
authored andcommitted
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: #64907 Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent ad7c670 commit d8a0f28

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
@@ -37,6 +37,28 @@ describe('node --run [command]', () => {
3737
assert.strictEqual(child.code, 1);
3838
});
3939

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

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL