mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 12:21:20 +00:00
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:
@@ -28,6 +28,7 @@ export function escapeShellArg(arg: string): string {
|
|||||||
.replace(/[\r\n\t]/g, ' ') // Replace newlines/tabs with space
|
.replace(/[\r\n\t]/g, ' ') // Replace newlines/tabs with space
|
||||||
.replace(/%/g, '%%') // Escape percent signs
|
.replace(/%/g, '%%') // Escape percent signs
|
||||||
.replace(/\^/g, '^^') // Escape carets
|
.replace(/\^/g, '^^') // Escape carets
|
||||||
|
.replace(/!/g, '^^!') // Escape exclamation marks (delayed expansion)
|
||||||
.replace(/"/g, '""') + // Escape quotes
|
.replace(/"/g, '""') + // Escape quotes
|
||||||
'"'
|
'"'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -75,5 +75,10 @@ describe('escapeShellArg', () => {
|
|||||||
const { escapeShellArg } = await import('../../../src/utils/shell-executor');
|
const { escapeShellArg } = await import('../../../src/utils/shell-executor');
|
||||||
expect(escapeShellArg('C:\\Program Files\\App')).toBe('"C:\\Program Files\\App"');
|
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^^!"');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user