Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codegens/curl/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ self = module.exports = {
isAsperandPresent = _.includes(rawBody, '@'),
// Use the long option if `@` is present in the request body otherwise follow user setting
optionName = isAsperandPresent ? '--data-raw' : form('-d', format);
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType)}${quoteType}`;
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType, true)}${quoteType}`;
break;
}

Expand Down
35 changes: 35 additions & 0 deletions codegens/curl/test/unit/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ describe('curl convert function', function () {
});
});

it('should escape backslash in raw bodies', function () {
request = new sdk.Request({
'method': 'POST',
'header': [
{
'key': 'Content-Type',
'value': 'application/json'
}
],
'body': {
'mode': 'raw',
'raw': '{ "foo": "\\" }'
},
'url': {
'raw': 'https://postman-echo.com/post',
'protocol': 'https',
'host': [
'postman-echo',
'com'
],
'path': [
'post'
]
}
});

convert(request, {}, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
}

expect(snippet).to.contain('{ "foo": "\\\\" }');
});
});

it('should return snippet with url in single quote(\')', function () {
request = new sdk.Request({
'method': 'POST',
Expand Down