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']);