Skip to content

Commit 260bca8

Browse files
author
Ankit Saini
authored
Merge pull request #687 from postmanlabs/feature/fix-backslash-escape
Don't escape backslash in raw bodies
2 parents 5a9668f + 2c2c07d commit 260bca8

File tree

4 files changed

+42
-37
lines changed

4 files changed

+42
-37
lines changed

codegens/curl/lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ self = module.exports = {
141141
isAsperandPresent = _.includes(rawBody, '@'),
142142
// Use the long option if `@` is present in the request body otherwise follow user setting
143143
optionName = isAsperandPresent ? '--data-raw' : form('-d', format);
144-
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType, true)}${quoteType}`;
144+
// eslint-disable-next-line max-len
145+
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType)}${quoteType}`;
145146
break;
146147
}
147148

codegens/curl/test/unit/convert.test.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,6 @@ describe('curl convert function', function () {
3434
});
3535
});
3636

37-
it('should escape backslash in raw bodies', function () {
38-
request = new sdk.Request({
39-
'method': 'POST',
40-
'header': [
41-
{
42-
'key': 'Content-Type',
43-
'value': 'application/json'
44-
}
45-
],
46-
'body': {
47-
'mode': 'raw',
48-
'raw': '{ "foo": "\\" }'
49-
},
50-
'url': {
51-
'raw': 'https://postman-echo.com/post',
52-
'protocol': 'https',
53-
'host': [
54-
'postman-echo',
55-
'com'
56-
],
57-
'path': [
58-
'post'
59-
]
60-
}
61-
});
62-
63-
convert(request, {}, function (error, snippet) {
64-
if (error) {
65-
expect.fail(null, null, error);
66-
}
67-
68-
expect(snippet).to.contain('{ "foo": "\\\\" }');
69-
});
70-
});
71-
7237
it('should return snippet with url in single quote(\')', function () {
7338
request = new sdk.Request({
7439
'method': 'POST',

codegens/r-httr/test/newman/newman.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('r-httr Converter', function () {
1313
fileName: 'snippet.r',
1414
// Run script required to run the generated code snippet
1515
runScript: 'Rscript snippet.r',
16-
skipCollections: ['redirectCollection', 'unsupportedMethods']
16+
skipCollections: ['redirectCollection', 'unsupportedMethods', 'rawBody']
1717
};
1818
runNewmanTest(convert, options, testConfig);
1919
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"info": {
3+
"_postman_id": "f52ee07d-6345-4220-89af-e6696b3c0122",
4+
"name": "Basic Collection",
5+
"description": "This collection contains requests that will be used to test validity of plugin created to convert postman request into code snippet of particular language.",
6+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
7+
},
8+
"item": [
9+
{
10+
"name": "POST raw with quoted text",
11+
"event": [],
12+
"request": {
13+
"method": "POST",
14+
"header": [
15+
{
16+
"key": "Content-Type",
17+
"value": "application/json"
18+
}
19+
],
20+
"body": {
21+
"mode": "raw",
22+
"raw": "{\n \"Hello\": \"{\\\"hello_world\\\": true}\"\n}"
23+
},
24+
"url": {
25+
"raw": "https://postman-echo.com/post",
26+
"protocol": "https",
27+
"host": [
28+
"postman-echo",
29+
"com"
30+
],
31+
"path": [
32+
"post"
33+
]
34+
}
35+
},
36+
"response": []
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)