fix(shell): escape ! for cmd.exe delayed expansion

Adds defensive escaping for exclamation marks in case delayed
expansion is enabled in the user's cmd.exe environment.
This commit is contained in:
kaitranntt
2026-02-05 10:45:07 -05:00
parent 48aa3cca30
commit 61bc54af05
2 changed files with 6 additions and 0 deletions
+1
View File
@@ -28,6 +28,7 @@ export function escapeShellArg(arg: string): string {
.replace(/[\r\n\t]/g, ' ') // Replace newlines/tabs with space
.replace(/%/g, '%%') // Escape percent signs
.replace(/\^/g, '^^') // Escape carets
.replace(/!/g, '^^!') // Escape exclamation marks (delayed expansion)
.replace(/"/g, '""') + // Escape quotes
'"'
);
+5
View File
@@ -75,5 +75,10 @@ describe('escapeShellArg', () => {
const { escapeShellArg } = await import('../../../src/utils/shell-executor');
expect(escapeShellArg('C:\\Program Files\\App')).toBe('"C:\\Program Files\\App"');
});
it('escapes exclamation marks for delayed expansion', async () => {
const { escapeShellArg } = await import('../../../src/utils/shell-executor');
expect(escapeShellArg('hello!')).toBe('"hello^^!"');
});
});
});