Skip to content

Commit 0802e2b

Browse files
authored
Fix handling of quoted args that contain spaces
Using `cx -H 'Accept: application/json'` was improperly sanitizing the args to `curl -i "-H" "Accept:" "application/json"` which is not the desired behavior.
1 parent 553d7f7 commit 0802e2b

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

utils/parse-curl.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,24 @@ var parseCurlCommand = function (curlCommand) {
164164
}
165165

166166
const sanitizeCurlArgs = function (args) {
167-
curlCommand = 'curl ' + args.join(' ');
168-
curlCommand = curlCommand.replace(/ -XPOST/, ' -X POST')
169-
curlCommand = curlCommand.replace(/ -XGET/, ' -X GET')
170-
curlCommand = curlCommand.replace(/ -XPUT/, ' -X PUT')
171-
curlCommand = curlCommand.replace(/ -XPATCH/, ' -X PATCH')
172-
curlCommand = curlCommand.replace(/ -XDELETE/, ' -X DELETE')
173-
curlCommand = curlCommand.trim()
174-
return curlCommand.split(' ').slice(1);
167+
const regexp = /^-X(POST|GET|PUT|PATCH|DELETE)$/;
168+
let sanitizedArgs = [];
169+
170+
for (let argI in args) {
171+
const arg = args[argI];
172+
if (regexp.test(arg)) {
173+
// Properly format args like `-XPOST` to `-X POST`
174+
sanitizedArgs.push('-X');
175+
sanitizedArgs.push(arg.match(regexp)[1]);
176+
continue;
177+
}
178+
sanitizedArgs.push(arg);
179+
}
180+
181+
return sanitizedArgs;
175182
}
176183

177184
module.exports = {
178185
parseCurlCommand,
179186
sanitizeCurlArgs
180-
}
187+
}

0 commit comments

Comments
 (0)