-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behavior
Description
It seems like argument parsing on Windows is not working correctly. Specifically, when using Git Bash on Windows (maybe the mix of Bash and Windows?).
I strongly suspect there's an issue with the argument parsing:
pact-js-cli/src/pact-standalone.ts
Lines 116 to 144 in d300b23
| function quoteCmdArg(arg: string) { | |
| return `"${arg.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; | |
| } | |
| function quotePwshArg(arg: string) { | |
| return `'${arg.replace(/'/g, "''")}'`; | |
| } | |
| function quotePosixShArg(arg: string) { | |
| return `'${arg.replace(/'/g, "'\\''")}'`; | |
| } | |
| function testWindowsExe(cmd: string, file: string) { | |
| return new RegExp(`^(?:.*\\\\)?${cmd}(?:\\.exe)?$`, 'i').test(file); | |
| } | |
| function parseArgs(unparsed_args: string[]) { | |
| if (isWindows === true) { | |
| const file = process.env['comspec'] || 'cmd.exe'; | |
| if (testWindowsExe('cmd', file) === true) { | |
| return unparsed_args.map((i) => quoteCmdArg(i)); | |
| } | |
| if (testWindowsExe('(powershell|pwsh)', file) || file.endsWith('/pwsh')) { | |
| return unparsed_args.map((i) => quotePwshArg(i)); | |
| } | |
| return unparsed_args; | |
| } | |
| return unparsed_args.map((i) => quotePosixShArg(i)); | |
| } |
In particular, I suspect it is not required at all:
-
On the input side,
process.argvhas all arguments properly escaped into individual strings -
On the invokation side, functions like
spawnwill ensure arguments are escaping correctly:spawn('ls', ['-lh', '/path/with/a space'])
Metadata
Metadata
Assignees
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behavior