Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/test/normalize_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down