From 46b259f5338bc254999c8fd6db8d7ce84895a62b Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Tue, 1 Dec 2026 13:24:59 +0000 Subject: [PATCH] fix: account for cmd's suffix stripping cmd does some funky nonsense where it strips `.` and spaces from commands. This change makes our "is it a windows command" check behave the same. --- src/normalize.ts | 2 +- src/test/normalize_test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/normalize.ts b/src/normalize.ts index 65c30a0..c8c8ef8 100644 --- a/src/normalize.ts +++ b/src/normalize.ts @@ -170,7 +170,7 @@ function resolveCommand(command: string, options: SpawnOptions): string | null { path.startsWith('"') && path.endsWith('"') && path.length > 1 ? path.slice(1, -1) : path; - const dest = resolvePath(cwd, unquoted, command); + const dest = resolvePath(cwd, unquoted, command).replace(/[. ]+$/, ''); for (const ext of extensions) { const destWithExt = dest + ext; diff --git a/src/test/normalize_test.ts b/src/test/normalize_test.ts index 8b37ff7..ef6b1fc 100644 --- a/src/test/normalize_test.ts +++ b/src/test/normalize_test.ts @@ -103,6 +103,18 @@ describe('normalizeSpawnCommand', () => { ); }); + test.each(['.', ' ', '. .'])( + 'double escapes meta chars in args to a batch file with trailing %j', + (suffix) => { + const cmdPath = path.join(fixturesPath, 'echo_args.cmd') + suffix; + const normalized = normalizeSpawnCommand(cmdPath, ['"&injected']); + + expect(normalized.args[4]).toBe( + `""${cmdPath}" ^^^"\\^^^"^^^&injected^^^""` + ); + } + ); + test('single escapes meta chars in args to a non-batch command', () => { const normalized = normalizeSpawnCommand('nonexistent', ['"&injected']);