Skip to content

Commit 7dcc69b

Browse files
authored
[FIX] cURL code snippet contains encoded value for special char + instead of char itself (#735)
* IMPORT-1337 do not encode + in query param * included in test * Added changes and test for all the codegens
1 parent 13a946d commit 7dcc69b

File tree

16 files changed

+76
-17
lines changed

16 files changed

+76
-17
lines changed

codegens/curl/lib/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ var self = module.exports = {
214214
},
215215

216216
/**
217-
* Encode param except the following characters- [,{,},],%
217+
* Encode param except the following characters- [,{,},],%,+
218218
*
219219
* @param {String} param
220220
* @returns {String}
@@ -225,6 +225,7 @@ var self = module.exports = {
225225
.replace(/%7B/g, '{')
226226
.replace(/%5D/g, ']')
227227
.replace(/%7D/g, '}')
228+
.replace(/%2B/g, '+')
228229
.replace(/%25/g, '%')
229230
.replace(/'/g, '%27');
230231
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,12 @@ describe('curl convert function', function () {
676676

677677
it('should not encode unresolved query params and ' +
678678
'encode every other query param, both present together', function () {
679-
rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b c\'';
679+
rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b+c\'';
680680
urlObject = new sdk.Url(rawUrl);
681681
outputUrlString = getUrlStringfromUrlObject(urlObject);
682682
expect(outputUrlString).to.not.include('key1=%7B%7Bvalue%7B%7B');
683-
expect(outputUrlString).to.not.include('key2=\'a b c\'');
684-
expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b%20c%27');
683+
expect(outputUrlString).to.not.include('key2=\'a b+c\'');
684+
expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b+c%27');
685685
});
686686

687687
it('should not encode query params that are already encoded', function () {

codegens/golang/lib/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const self = module.exports = {
109109
},
110110

111111
/**
112-
* Encode param except the following characters- [,{,},],%
112+
* Encode param except the following characters- [,{,},],%,+
113113
*
114114
* @param {String} param
115115
* @returns {String}
@@ -120,6 +120,7 @@ const self = module.exports = {
120120
.replace(/%7B/g, '{')
121121
.replace(/%5D/g, ']')
122122
.replace(/%7D/g, '}')
123+
.replace(/%2B/g, '+')
123124
.replace(/%25/g, '%')
124125
.replace(/'/g, '%27');
125126
},

codegens/golang/test/unit/convert.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var expect = require('chai').expect,
22
sdk = require('postman-collection'),
3-
convert = require('../../index').convert;
3+
convert = require('../../index').convert,
4+
getUrlStringfromUrlObject = require('../../lib/util').getUrlStringfromUrlObject;
45

56
describe('Golang convert function', function () {
67
describe('Convert function', function () {
@@ -253,5 +254,15 @@ describe('Golang convert function', function () {
253254
});
254255
});
255256
});
257+
258+
it('should not encode unresolved query params and ' +
259+
'encode every other query param, both present together', function () {
260+
let rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b+c\'',
261+
urlObject = new sdk.Url(rawUrl),
262+
outputUrlString = getUrlStringfromUrlObject(urlObject);
263+
expect(outputUrlString).to.not.include('key1=%7B%7Bvalue%7B%7B');
264+
expect(outputUrlString).to.not.include('key2=\'a b+c\'');
265+
expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b+c%27');
266+
});
256267
});
257268
});

codegens/java-unirest/lib/parseRequest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var _ = require('./lodash'),
33
sanitize = require('./util').sanitize;
44

55
/**
6-
* Encode param except the following characters- [,],%
6+
* Encode param except the following characters- [,],%,+
77
* Characters { and } are kept encoded because unirest does not support them
88
*
99
* @param {String} param
@@ -13,6 +13,7 @@ function encodeParam (param) {
1313
return encodeURIComponent(param)
1414
.replace(/%5B/g, '[')
1515
.replace(/%5D/g, ']')
16+
.replace(/%2B/g, '+')
1617
.replace(/%25/g, '%')
1718
.replace(/'/g, '%27');
1819
}

codegens/java-unirest/test/unit/convert.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,12 @@ describe('java unirest convert function for test collection', function () {
500500

501501
it('should not encode unresolved query params and ' +
502502
'encode every other query param, both present together', function () {
503-
rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b c\'';
503+
rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b+c\'';
504504
urlObject = new sdk.Url(rawUrl);
505505
outputUrlString = getUrlStringfromUrlObject(urlObject);
506506
expect(outputUrlString).to.include('key1=%7B%7Bvalue%7D%7D');
507-
expect(outputUrlString).to.not.include('key2=\'a b c\'');
508-
expect(outputUrlString).to.equal('https://postman-echo.com/get?key1=%7B%7Bvalue%7D%7D&key2=%27a%20b%20c%27');
507+
expect(outputUrlString).to.not.include('key2=\'a b+c\'');
508+
expect(outputUrlString).to.equal('https://postman-echo.com/get?key1=%7B%7Bvalue%7D%7D&key2=%27a%20b+c%27');
509509
});
510510

511511
it('should discard disabled query params', function () {

codegens/js-xhr/lib/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const self = module.exports = {
158158
},
159159

160160
/**
161-
* Encode param except the following characters- [,{,},],%
161+
* Encode param except the following characters- [,{,},],%,+
162162
*
163163
* @param {String} param
164164
* @returns {String}
@@ -169,6 +169,7 @@ const self = module.exports = {
169169
.replace(/%7B/g, '{')
170170
.replace(/%5D/g, ']')
171171
.replace(/%7D/g, '}')
172+
.replace(/%2B/g, '+')
172173
.replace(/%25/g, '%')
173174
.replace(/'/g, '%27');
174175
},

codegens/js-xhr/test/unit/convert.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var expect = require('chai').expect,
22
sdk = require('postman-collection'),
33
sanitize = require('../../lib/util.js').sanitize,
4-
4+
getUrlStringfromUrlObject = require('../../lib/util').getUrlStringfromUrlObject,
55
convert = require('../../index').convert,
66
getOptions = require('../../index').getOptions;
77

@@ -162,6 +162,15 @@ describe('js-xhr convert function', function () {
162162
it('should trim input string when needed', function () {
163163
expect(sanitize('inputString ', true)).to.equal('inputString');
164164
});
165+
it('should not encode unresolved query params and ' +
166+
'encode every other query param, both present together', function () {
167+
let rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b+c\'',
168+
urlObject = new sdk.Url(rawUrl),
169+
outputUrlString = getUrlStringfromUrlObject(urlObject);
170+
expect(outputUrlString).to.not.include('key1=%7B%7Bvalue%7B%7B');
171+
expect(outputUrlString).to.not.include('key2=\'a b+c\'');
172+
expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b+c%27');
173+
});
165174
});
166175

167176
describe('POST Form data Request', function () {

codegens/libcurl/lib/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const self = module.exports = {
160160
},
161161

162162
/**
163-
* Encode param except the following characters- [,{,},],%
163+
* Encode param except the following characters- [,{,},],%,+
164164
*
165165
* @param {String} param
166166
* @returns {String}
@@ -171,6 +171,7 @@ const self = module.exports = {
171171
.replace(/%7B/g, '{')
172172
.replace(/%5D/g, ']')
173173
.replace(/%7D/g, '}')
174+
.replace(/%2B/g, '+')
174175
.replace(/%25/g, '%')
175176
.replace(/'/g, '%27');
176177
},

codegens/libcurl/test/unit/convert.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var expect = require('chai').expect,
22
sdk = require('postman-collection'),
33
convert = require('../../index').convert,
44
getOptions = require('../../index').getOptions,
5+
getUrlStringfromUrlObject = require('../../lib/util').getUrlStringfromUrlObject,
56
sanitize = require('../../lib/util').sanitize,
67
mainCollection = require('../../../../test/codegen/newman/fixtures/basicCollection.json');
78

@@ -207,5 +208,14 @@ describe('libcurl convert function', function () {
207208
expect(sanitize('inputString ', true)).to.equal('inputString');
208209
});
209210

211+
it('should not encode unresolved query params and ' +
212+
'encode every other query param, both present together', function () {
213+
let rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b+c\'',
214+
urlObject = new sdk.Url(rawUrl),
215+
outputUrlString = getUrlStringfromUrlObject(urlObject);
216+
expect(outputUrlString).to.not.include('key1=%7B%7Bvalue%7B%7B');
217+
expect(outputUrlString).to.not.include('key2=\'a b+c\'');
218+
expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b+c%27');
219+
});
210220
});
211221
});

0 commit comments

Comments
 (0)