| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ad7c670 commit d8a0f28
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,11 @@ ProcessRunner::ProcessRunner(std::shared_ptr<InitializationResultImpl> result, | |||
| 60 | 60 | } | |
| 61 | 61 | ||
| 62 | 62 | #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())) { | ||
| 64 | 68 | // If the file is cmd.exe, use the following command line arguments: | |
| 65 | 69 | // "/c" Carries out the command and exit. | |
| 66 | 70 | // "/d" Disables execution of AutoRun commands. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,28 @@ describe('node --run [command]', () => { | |||
| 37 | 37 | assert.strictEqual(child.code, 1); | |
| 38 | 38 | }); | |
| 39 | 39 | ||
| 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 | + | ||
| 40 | 62 | it('adds node_modules/.bin to path', async () => { | |
| 41 | 63 | const child = await common.spawnPromisified( | |
| 42 | 64 | process.execPath, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments