Skip to content

Commit d3b0d95

Browse files
committed
Properly escape already escaped double quotes in curl body
1 parent 8799e9b commit d3b0d95

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
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/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ self = module.exports = {
7676
// If the header value is an empty string then add a semicolon after key
7777
// otherwise the header would be ignored by curl
7878
if (header.value) {
79-
snippet += `: ${sanitize(header.value, false, quoteType)}${quoteType}`;
79+
snippet += `: ${sanitize(header.value, false, quoteType, true)}${quoteType}`;
8080
}
8181
else {
8282
snippet += ';' + quoteType;

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 '\''

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)