Skip to content

Commit 2d9f862

Browse files
author
Ankit Saini
authored
Merge pull request #478 from postmanlabs/issue-476
Properly escape already escaped double quotes in curl body
2 parents fb6d0ba + 26630a1 commit 2d9f862

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"node": true,
99
"es6": true
1010
},
11+
"parserOptions": {
12+
"ecmaVersion": 2018
13+
},
1114
"rules": {
1215
// Possible Errors
1316
"for-direction": "error",

codegens/curl/lib/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var self = module.exports = {
55
*
66
* @param {String} inputString
77
* @param {Boolean} [trim] - indicates whether to trim string or not
8-
* @param {Boolean} [quoteType] - indicates which quoteType has to be escaped
8+
* @param {String} [quoteType] - indicates which quoteType has to be escaped
99
* @param {Boolean} [backSlash] - indicates whether to escape backslash(\\)
1010
* @returns {String}
1111
*/
@@ -20,6 +20,8 @@ var self = module.exports = {
2020

2121
if (quoteType === '"') {
2222
inputString = inputString.replace(/"/g, '\\"');
23+
// Escape backslash if double quote was already escaped before call to sanitize
24+
inputString = inputString.replace(/(?<!\\)\\\\"/g, '\\\\\\"');
2325
}
2426
else if (quoteType === '\'') {
2527
// for curl escaping of single quotes inside single quotes involves changing of ' to '\''

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,38 @@ describe('curl convert function', function () {
499499
});
500500
});
501501

502+
it('should not add appropriate escaping characters when quote type is "double"', function () {
503+
var request = new sdk.Request({
504+
'method': 'POST',
505+
'header': [],
506+
'body': {
507+
'mode': 'graphql',
508+
'graphql': {
509+
'query': '{\n findScenes(\n filter: {per_page: 0}\n scene_filter: {is_missing: "performers"}){\n count\n scenes {\n id\n title\n path\n }\n }\n}', // eslint-disable-line
510+
'variables': '{\n\t"variable_key": "variable_value"\n}'
511+
}
512+
},
513+
'url': {
514+
'raw': 'https://postman-echo.com/post',
515+
'protocol': 'https',
516+
'host': [
517+
'postman-echo',
518+
'com'
519+
],
520+
'path': [
521+
'post'
522+
]
523+
}
524+
});
525+
convert(request, { quoteType: 'double', lineContinuationCharacter: '^' }, function (error, snippet) {
526+
if (error) {
527+
expect.fail(null, null, error);
528+
}
529+
530+
expect(snippet).to.include('{\\"query\\":\\"{\\n findScenes(\\n filter: {per_page: 0}\\n scene_filter: {is_missing: \\\\\\"performers\\\\\\"})'); // eslint-disable-line
531+
});
532+
});
533+
502534
describe('getUrlStringfromUrlObject function', function () {
503535
var rawUrl, urlObject, outputUrlString;
504536

test/codegen/newman/fixtures/basicCollection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
"body": {
289289
"mode": "graphql",
290290
"graphql": {
291-
"query": "{\n body{\n graphql\n }\n}",
291+
"query": "{\n findScenes(\n filter: {per_page: 0}\n scene_filter: {is_missing: \"performers\"}){\n count\n scenes {\n id\n title\n path\n }\n }\n}",
292292
"variables": "{\n\t\"variable_key\": \"variable_value\"\n}"
293293
}
294294
},

0 commit comments

Comments
 (0)