From 400f7b7698f9c10435b4abffca8376284e44d0c7 Mon Sep 17 00:00:00 2001 From: SK Akram Date: Sat, 27 Dec 2025 05:54:39 +0000 Subject: [PATCH] fix: correctly escape empty shell arguments --- packages/core/src/utils/shell-utils.test.ts | 6 +++--- packages/core/src/utils/shell-utils.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/src/utils/shell-utils.test.ts b/packages/core/src/utils/shell-utils.test.ts index e87c90b..77e60e3 100644 --- a/packages/core/src/utils/shell-utils.test.ts +++ b/packages/core/src/utils/shell-utils.test.ts @@ -320,7 +320,7 @@ describe('escapeShellArg', () => { it('should handle empty strings', () => { const result = escapeShellArg('', 'bash'); - expect(result).toBe(''); + expect(result).toBe("''"); expect(mockQuote).not.toHaveBeenCalled(); }); }); @@ -339,7 +339,7 @@ describe('escapeShellArg', () => { it('should handle empty strings', () => { const result = escapeShellArg('', 'cmd'); - expect(result).toBe(''); + expect(result).toBe('""'); }); }); @@ -361,7 +361,7 @@ describe('escapeShellArg', () => { it('should handle empty strings', () => { const result = escapeShellArg('', 'powershell'); - expect(result).toBe(''); + expect(result).toBe("''"); }); }); }); diff --git a/packages/core/src/utils/shell-utils.ts b/packages/core/src/utils/shell-utils.ts index e0e62ec..91dbc48 100644 --- a/packages/core/src/utils/shell-utils.ts +++ b/packages/core/src/utils/shell-utils.ts @@ -89,8 +89,8 @@ export const isWindows = () => os.platform() === 'win32'; * @returns The shell-escaped string. */ export function escapeShellArg(arg: string, shell: ShellType): string { - if (!arg) { - return ''; + if (arg === '') { + return shell === 'cmd' ? '""' : "''"; } switch (shell) {