fix(curl): properly wrap JSON payload (#31)

This commit is contained in:
Mazen Touati
2026-01-04 19:47:20 +01:00
committed by GitHub
parent 07f0106b16
commit 8bdd510f17
2 changed files with 3 additions and 3 deletions

View File

@@ -55,7 +55,7 @@ describe('generateCurlCommand', () => {
expect(command).toContain('"https://api.example.com/users?page=1"');
expect(command).toContain('-H "Authorization: Bearer token"');
expect(command).toContain('-H "Accept: application/json"');
expect(command).toContain('{"name":"Jane"}');
expect(command).toContain('\'{"name":"Jane"}\'');
expect(hasSpecialAuth).toBe(false);
});
@@ -98,7 +98,7 @@ describe('generateCurlCommand', () => {
expect(command).toContain('-H "Authorization: Bearer token"');
expect(command).toContain('-H "Accept: application/json"');
expect(command).toContain(
'{"user":{"firstName":"Jane","lastName":"Doe"},"username":"foobar"}',
'\'{"user":{"firstName":"Jane","lastName":"Doe"},"username":"foobar"}\'',
);
expect(hasSpecialAuth).toBe(false);
});

View File

@@ -255,7 +255,7 @@ function transformRequestBodyToKeyValuePairs(
*/
function convertBodyValueToRequestParts(bodyValue: string | FormData): string[] {
if (typeof bodyValue === 'string') {
return [`-d ${bodyValue}`];
return [`-d '${bodyValue}'`];
}
return convertFormDataToCUrlFields(bodyValue);