diff --git a/packages/web/src/utils/escapeArguments.spec.ts b/packages/web/src/utils/escapeArguments.spec.ts index 93edcae2b..d3462941d 100644 --- a/packages/web/src/utils/escapeArguments.spec.ts +++ b/packages/web/src/utils/escapeArguments.spec.ts @@ -17,5 +17,13 @@ describe('utils', () => { it('should handle array with multiple arguments with spaces', () => { expect(escapeArguments(['ab c', 'de f'])).toEqual(['"ab c"', '"de f"']); }); + + it('should handle array with multiple arguments with quotes', () => { + expect(escapeArguments(['ab"c', 'de"f'])).toEqual(['ab"c', 'de"f']); + }); + + it('should handle array with multiple arguments with spaces and quotes', () => { + expect(escapeArguments(['ab"c', 'de f'])).toEqual(['ab"c', '"de f"']); + }); }); }); diff --git a/packages/web/src/utils/escapeArguments.ts b/packages/web/src/utils/escapeArguments.ts index 88bb751e8..a3e063ae9 100644 --- a/packages/web/src/utils/escapeArguments.ts +++ b/packages/web/src/utils/escapeArguments.ts @@ -1,3 +1,7 @@ export const escapeArguments = (args: string[]) => { - return args.map(arg => (arg.includes(' ') ? `"${arg}"` : arg)); + return args.map(arg => { + const escapedArg = arg.replace(/(")/g, '\\$1'); + + return /\s/.test(escapedArg) ? `"${escapedArg}"` : escapedArg; + }); };