From c076f20c236b38a3b8eb84ea6eda640f71026fde Mon Sep 17 00:00:00 2001 From: Dhwaneet Bhatt Date: Tue, 18 Apr 2023 10:35:38 +0530 Subject: [PATCH 1/3] Fix an issue where % was getting double encoded in query params --- codegens/curl/lib/util.js | 3 +- codegens/curl/test/unit/convert.test.js | 7 ++ codegens/golang/lib/index.js | 3 +- codegens/golang/lib/util.js | 116 +++++++++++++++--- codegens/java-okhttp/lib/okhttp.js | 2 +- .../java-okhttp/test/newman/newman.test.js | 6 +- .../java-okhttp/test/unit/convert.test.js | 4 +- codegens/java-unirest/lib/parseRequest.js | 5 +- codegens/java-unirest/lib/unirest.js | 2 +- .../java-unirest/test/newman/newman.test.js | 6 +- .../java-unirest/test/unit/convert.test.js | 21 ++-- codegens/js-xhr/lib/index.js | 3 +- codegens/js-xhr/lib/util.js | 88 ++++++++++++- codegens/libcurl/lib/index.js | 3 +- codegens/libcurl/lib/util.js | 88 ++++++++++++- .../nodejs-native/test/newman/newman.test.js | 6 +- .../objective-c/test/newman/newman.test.js | 3 +- codegens/ocaml-cohttp/lib/ocaml.js | 3 +- codegens/ocaml-cohttp/lib/util.js | 88 ++++++++++++- codegens/php-curl/lib/php-curl.js | 7 +- codegens/php-curl/lib/util/sanitize.js | 88 ++++++++++++- .../test/newman/newman.test.js | 3 +- codegens/swift/lib/util.js | 3 +- codegens/swift/test/unit/convert.test.js | 7 ++ .../fixtures/queryParamsCollection.json | 31 +++++ 25 files changed, 542 insertions(+), 54 deletions(-) create mode 100644 test/codegen/newman/fixtures/queryParamsCollection.json diff --git a/codegens/curl/lib/util.js b/codegens/curl/lib/util.js index 2b9e93d97..9c7229f68 100644 --- a/codegens/curl/lib/util.js +++ b/codegens/curl/lib/util.js @@ -207,7 +207,7 @@ var self = module.exports = { }, /** - * Encode param except the following characters- [,{,},] + * Encode param except the following characters- [,{,},],% * * @param {String} param * @returns {String} @@ -218,6 +218,7 @@ var self = module.exports = { .replace(/%7B/g, '{') .replace(/%5D/g, ']') .replace(/%7D/g, '}') + .replace(/%25/g, '%') .replace(/'/g, '%27'); }, diff --git a/codegens/curl/test/unit/convert.test.js b/codegens/curl/test/unit/convert.test.js index 5482940ed..975240399 100644 --- a/codegens/curl/test/unit/convert.test.js +++ b/codegens/curl/test/unit/convert.test.js @@ -650,6 +650,13 @@ describe('curl convert function', function () { expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b%20c%27'); }); + it('should not encode query params that are already encoded', function () { + rawUrl = 'https://postman-echo.com/get?query=urn%3Ali%3Afoo%3A62324'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal('https://postman-echo.com/get?query=urn%3Ali%3Afoo%3A62324'); + }); + it('should discard disabled query params', function () { urlObject = new sdk.Url({ protocol: 'https', diff --git a/codegens/golang/lib/index.js b/codegens/golang/lib/index.js index 46d936c01..c2fcd0dae 100644 --- a/codegens/golang/lib/index.js +++ b/codegens/golang/lib/index.js @@ -3,6 +3,7 @@ var _ = require('./lodash'), sanitizeMultiline = require('./util').sanitizeMultiline, sanitizeOptions = require('./util').sanitizeOptions, addFormParam = require('./util').addFormParam, + getUrlStringfromUrlObject = require('./util').getUrlStringfromUrlObject, isFile = false, self; @@ -243,7 +244,7 @@ self = module.exports = { } codeSnippet += `${indent}"net/http"\n${indent}"io/ioutil"\n)\n\n`; - codeSnippet += `func main() {\n\n${indent}url := "${encodeURI(request.url.toString())}"\n`; + codeSnippet += `func main() {\n\n${indent}url := "${getUrlStringfromUrlObject(request.url)}"\n`; codeSnippet += `${indent}method := "${request.method}"\n\n`; if (bodySnippet !== '') { diff --git a/codegens/golang/lib/util.js b/codegens/golang/lib/util.js index 3745c9bd7..005da12a7 100644 --- a/codegens/golang/lib/util.js +++ b/codegens/golang/lib/util.js @@ -1,12 +1,14 @@ -module.exports = { +const _ = require('./lodash'); + +const self = module.exports = { /** - * sanitizes input string by handling escape characters eg: converts '''' to '\'\'' - * and trim input if required - * - * @param {String} inputString - * @param {Boolean} [trim] - indicates whether to trim string or not - * @returns {String} - */ + * sanitizes input string by handling escape characters eg: converts '''' to '\'\'' + * and trim input if required + * + * @param {String} inputString + * @param {Boolean} [trim] - indicates whether to trim string or not + * @returns {String} + */ sanitize: function (inputString, trim) { if (typeof inputString !== 'string') { return ''; @@ -20,13 +22,13 @@ module.exports = { }, /** - * sanitizes input string by handling escape characters eg: converts '''' to '\'\'' - * and trim input if required - * - * @param {String} inputString - * @param {Boolean} [trim] - indicates whether to trim string or not - * @returns {String} - */ + * sanitizes input string by handling escape characters eg: converts '''' to '\'\'' + * and trim input if required + * + * @param {String} inputString + * @param {Boolean} [trim] - indicates whether to trim string or not + * @returns {String} + */ sanitizeMultiline: function (inputString, trim) { if (typeof inputString !== 'string') { return ''; @@ -38,6 +40,90 @@ module.exports = { }, + /** + * + * @param {Object} urlObject The request sdk request.url object + * @returns {String} The final string after parsing all the parameters of the url including + * protocol, auth, host, port, path, query, hash + * This will be used because the url.toString() method returned the URL with non encoded query string + * and hence a manual call is made to getQueryString() method with encode option set as true. + */ + getUrlStringfromUrlObject: function (urlObject) { + var url = ''; + if (!urlObject) { + return url; + } + if (urlObject.protocol) { + url += (urlObject.protocol.endsWith('://') ? urlObject.protocol : urlObject.protocol + '://'); + } + if (urlObject.auth && urlObject.auth.user) { + url = url + ((urlObject.auth.password) ? + urlObject.auth.user + ':' + urlObject.auth.password : urlObject.auth.user) + '@'; + } + if (urlObject.host) { + url += urlObject.getHost(); + } + if (urlObject.port) { + url += ':' + urlObject.port.toString(); + } + if (urlObject.path) { + url += urlObject.getPath(); + } + if (urlObject.query && urlObject.query.count()) { + let queryString = self.getQueryString(urlObject); + queryString && (url += '?' + queryString); + } + if (urlObject.hash) { + url += '#' + urlObject.hash; + } + + return self.sanitize(url, false); + }, + + /** + * @param {Object} urlObject + * @returns {String} + */ + getQueryString: function (urlObject) { + let isFirstParam = true, + params = _.get(urlObject, 'query.members'), + result = ''; + if (Array.isArray(params)) { + result = _.reduce(params, function (result, param) { + if (param.disabled === true) { + return result; + } + + if (isFirstParam) { + isFirstParam = false; + } + else { + result += '&'; + } + + return result + self.encodeParam(param.key) + '=' + self.encodeParam(param.value); + }, result); + } + + return result; + }, + + /** + * Encode param except the following characters- [,{,},],% + * + * @param {String} param + * @returns {String} + */ + encodeParam: function (param) { + return encodeURIComponent(param) + .replace(/%5B/g, '[') + .replace(/%7B/g, '{') + .replace(/%5D/g, ']') + .replace(/%7D/g, '}') + .replace(/%25/g, '%') + .replace(/'/g, '%27'); + }, + /** * sanitizes input options * diff --git a/codegens/java-okhttp/lib/okhttp.js b/codegens/java-okhttp/lib/okhttp.js index ee2aec561..81b07d321 100644 --- a/codegens/java-okhttp/lib/okhttp.js +++ b/codegens/java-okhttp/lib/okhttp.js @@ -189,7 +189,7 @@ function convert (request, options, callback) { if (options.includeBoilerplate) { headerSnippet = 'import java.io.*;\n' + 'import okhttp3.*;\n' + - 'public class main {\n' + + 'public class Main {\n' + indentString + 'public static void main(String []args) throws IOException{\n'; footerSnippet = indentString.repeat(2) + 'System.out.println(response.body().string());\n' + indentString + '}\n}\n'; diff --git a/codegens/java-okhttp/test/newman/newman.test.js b/codegens/java-okhttp/test/newman/newman.test.js index f2dc6fb3f..47deffd5b 100644 --- a/codegens/java-okhttp/test/newman/newman.test.js +++ b/codegens/java-okhttp/test/newman/newman.test.js @@ -4,9 +4,9 @@ var runNewmanTest = require('../../../../test/codegen/newman/newmanTestUtil').ru describe.skip('convert for different request types', function () { var options = {indentCount: 3, indentType: 'Space', includeBoilerplate: true}, testConfig = { - compileScript: 'javac -cp *: main.java', - runScript: 'java -cp *: main', - fileName: 'main.java', + compileScript: 'javac -cp *: Main.java', + runScript: 'java -cp *: Main', + fileName: 'Main.java', skipCollections: ['redirectCollection'] }; runNewmanTest(convert, options, testConfig); diff --git a/codegens/java-okhttp/test/unit/convert.test.js b/codegens/java-okhttp/test/unit/convert.test.js index f2206cb72..52e0eb9d8 100644 --- a/codegens/java-okhttp/test/unit/convert.test.js +++ b/codegens/java-okhttp/test/unit/convert.test.js @@ -25,7 +25,7 @@ describe('okhttp convert function', function () { } snippetArray = snippet.split('\n'); for (var i = 0; i < snippetArray.length; i++) { - if (snippetArray[i].startsWith('public class main {')) { + if (snippetArray[i].startsWith('public class Main {')) { expect(snippetArray[i + 1].substr(0, 4)).to.equal(SINGLE_SPACE.repeat(4)); expect(snippetArray[i + 1].charAt(4)).to.not.equal(SINGLE_SPACE); } @@ -39,7 +39,7 @@ describe('okhttp convert function', function () { expect.fail(null, null, error); return; } - expect(snippet).to.include('import java.io.*;\nimport okhttp3.*;\npublic class main {\n'); + expect(snippet).to.include('import java.io.*;\nimport okhttp3.*;\npublic class Main {\n'); }); }); diff --git a/codegens/java-unirest/lib/parseRequest.js b/codegens/java-unirest/lib/parseRequest.js index 85f589693..8f90d59c2 100644 --- a/codegens/java-unirest/lib/parseRequest.js +++ b/codegens/java-unirest/lib/parseRequest.js @@ -3,7 +3,7 @@ var _ = require('./lodash'), sanitize = require('./util').sanitize; /** - * Encode param except the following characters- [,{,},] + * Encode param except the following characters- [,{,},],% * * @param {String} param * @returns {String} @@ -11,9 +11,8 @@ var _ = require('./lodash'), function encodeParam (param) { return encodeURIComponent(param) .replace(/%5B/g, '[') - .replace(/%7B/g, '{') .replace(/%5D/g, ']') - .replace(/%7D/g, '}') + .replace(/%25/g, '%') .replace(/'/g, '%27'); } diff --git a/codegens/java-unirest/lib/unirest.js b/codegens/java-unirest/lib/unirest.js index f72043563..540aee882 100644 --- a/codegens/java-unirest/lib/unirest.js +++ b/codegens/java-unirest/lib/unirest.js @@ -186,7 +186,7 @@ function convert (request, options, callback) { if (options.includeBoilerplate) { headerSnippet = 'import com.mashape.unirest.http.*;\n' + 'import java.io.*;\n' + - 'public class main {\n' + + 'public class Main {\n' + indentString + 'public static void main(String []args) throws Exception{\n'; footerSnippet = indentString.repeat(2) + 'System.out.println(response.getBody());\n' + indentString + '}\n}\n'; diff --git a/codegens/java-unirest/test/newman/newman.test.js b/codegens/java-unirest/test/newman/newman.test.js index 2eae22b44..5b8620407 100644 --- a/codegens/java-unirest/test/newman/newman.test.js +++ b/codegens/java-unirest/test/newman/newman.test.js @@ -3,9 +3,9 @@ var runNewmanTest = require('../../../../test/codegen/newman/newmanTestUtil').ru describe('Convert for different types of request', function () { var testConfig = { - runScript: 'java -cp *: main', - compileScript: 'javac -cp *: main.java', - fileName: 'main.java', + runScript: 'java -cp *: Main', + compileScript: 'javac -cp *: Main.java', + fileName: 'Main.java', skipCollections: ['formdataCollection', 'emptyFormdataCollection', 'unsupportedMethods'] }, options = {includeBoilerplate: true}; diff --git a/codegens/java-unirest/test/unit/convert.test.js b/codegens/java-unirest/test/unit/convert.test.js index a400aff77..02ff19310 100644 --- a/codegens/java-unirest/test/unit/convert.test.js +++ b/codegens/java-unirest/test/unit/convert.test.js @@ -134,7 +134,7 @@ describe('java unirest convert function for test collection', function () { }; headerSnippet = 'import com.mashape.unirest.http.*;\n' + 'import java.io.*;\n' + - 'public class main {\n' + + 'public class Main {\n' + indentString + 'public static void main(String []args) throws Exception{\n'; footerSnippet = indentString.repeat(2) + 'System.out.println(response.getBody());\n' + indentString + '}\n}\n'; @@ -218,8 +218,8 @@ describe('java unirest convert function for test collection', function () { expect.fail(null, null, error); } expect(snippet).to.be.a('string'); - expect(snippet).to.include('http://postman-echo.com/post?a={{xyz}}'); - expect(snippet).to.not.include('http://postman-echo.com/post?a=%7B%7Bxyz%7D%7D'); + expect(snippet).to.not.include('http://postman-echo.com/post?a={{xyz}}'); + expect(snippet).to.include('http://postman-echo.com/post?a=%7B%7Bxyz%7D%7D'); }); }); @@ -479,8 +479,8 @@ describe('java unirest convert function for test collection', function () { rawUrl = 'https://postman-echo.com/get?key={{value}}'; urlObject = new sdk.Url(rawUrl); outputUrlString = getUrlStringfromUrlObject(urlObject); - expect(outputUrlString).to.not.include('key=%7B%7Bvalue%7B%7B'); - expect(outputUrlString).to.equal(rawUrl); + expect(outputUrlString).to.include('key=%7B%7Bvalue%7D%7D'); + expect(outputUrlString).to.equal('https://postman-echo.com/get?key=%7B%7Bvalue%7D%7D'); }); it('should encode query params other than unresolved variables', function () { @@ -491,14 +491,21 @@ describe('java unirest convert function for test collection', function () { expect(outputUrlString).to.equal('https://postman-echo.com/get?key=%27a%20b%20c%27'); }); + it('should not encode query params that are already encoded', function () { + rawUrl = 'https://postman-echo.com/get?query=urn%3Ali%3Afoo%3A62324'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal('https://postman-echo.com/get?query=urn%3Ali%3Afoo%3A62324'); + }); + it('should not encode unresolved query params and ' + 'encode every other query param, both present together', function () { rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b c\''; urlObject = new sdk.Url(rawUrl); outputUrlString = getUrlStringfromUrlObject(urlObject); - expect(outputUrlString).to.not.include('key1=%7B%7Bvalue%7B%7B'); + expect(outputUrlString).to.include('key1=%7B%7Bvalue%7D%7D'); expect(outputUrlString).to.not.include('key2=\'a b c\''); - expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b%20c%27'); + expect(outputUrlString).to.equal('https://postman-echo.com/get?key1=%7B%7Bvalue%7D%7D&key2=%27a%20b%20c%27'); }); it('should discard disabled query params', function () { diff --git a/codegens/js-xhr/lib/index.js b/codegens/js-xhr/lib/index.js index 8ec239c76..1b9be55f3 100644 --- a/codegens/js-xhr/lib/index.js +++ b/codegens/js-xhr/lib/index.js @@ -2,6 +2,7 @@ var _ = require('./lodash'), sanitize = require('./util').sanitize, sanitizeOptions = require('./util').sanitizeOptions, addFormParam = require('./util').addFormParam, + getUrlStringfromUrlObject = require('./util').getUrlStringfromUrlObject, path = require('path'); /** @@ -278,7 +279,7 @@ function convert (request, options, callback) { codeSnippet += `${indent.repeat(2)}console.log(this.responseText);\n`; codeSnippet += `${indent}}\n});\n\n`; - codeSnippet += `xhr.open("${request.method}", "${encodeURI(request.url.toString())}");\n`; + codeSnippet += `xhr.open("${request.method}", "${getUrlStringfromUrlObject(request.url)}");\n`; if (options.requestTimeout) { codeSnippet += `xhr.timeout = ${options.requestTimeout};\n`; codeSnippet += 'xhr.addEventListener("ontimeout", function(e) {\n'; diff --git a/codegens/js-xhr/lib/util.js b/codegens/js-xhr/lib/util.js index 71b49c7c6..525862b57 100644 --- a/codegens/js-xhr/lib/util.js +++ b/codegens/js-xhr/lib/util.js @@ -1,4 +1,6 @@ -module.exports = { +const _ = require('./lodash'); + +const self = module.exports = { /** * sanitizes input string by handling escape characters eg: converts '''' to '\'\'' * and trim input if required @@ -87,6 +89,90 @@ module.exports = { return result; }, + /** + * + * @param {Object} urlObject The request sdk request.url object + * @returns {String} The final string after parsing all the parameters of the url including + * protocol, auth, host, port, path, query, hash + * This will be used because the url.toString() method returned the URL with non encoded query string + * and hence a manual call is made to getQueryString() method with encode option set as true. + */ + getUrlStringfromUrlObject: function (urlObject) { + var url = ''; + if (!urlObject) { + return url; + } + if (urlObject.protocol) { + url += (urlObject.protocol.endsWith('://') ? urlObject.protocol : urlObject.protocol + '://'); + } + if (urlObject.auth && urlObject.auth.user) { + url = url + ((urlObject.auth.password) ? + urlObject.auth.user + ':' + urlObject.auth.password : urlObject.auth.user) + '@'; + } + if (urlObject.host) { + url += urlObject.getHost(); + } + if (urlObject.port) { + url += ':' + urlObject.port.toString(); + } + if (urlObject.path) { + url += urlObject.getPath(); + } + if (urlObject.query && urlObject.query.count()) { + let queryString = self.getQueryString(urlObject); + queryString && (url += '?' + queryString); + } + if (urlObject.hash) { + url += '#' + urlObject.hash; + } + + return self.sanitize(url, false); + }, + + /** + * @param {Object} urlObject + * @returns {String} + */ + getQueryString: function (urlObject) { + let isFirstParam = true, + params = _.get(urlObject, 'query.members'), + result = ''; + if (Array.isArray(params)) { + result = _.reduce(params, function (result, param) { + if (param.disabled === true) { + return result; + } + + if (isFirstParam) { + isFirstParam = false; + } + else { + result += '&'; + } + + return result + self.encodeParam(param.key) + '=' + self.encodeParam(param.value); + }, result); + } + + return result; + }, + + /** + * Encode param except the following characters- [,{,},],% + * + * @param {String} param + * @returns {String} + */ + encodeParam: function (param) { + return encodeURIComponent(param) + .replace(/%5B/g, '[') + .replace(/%7B/g, '{') + .replace(/%5D/g, ']') + .replace(/%7D/g, '}') + .replace(/%25/g, '%') + .replace(/'/g, '%27'); + }, + /** * * @param {Array} array - form data array diff --git a/codegens/libcurl/lib/index.js b/codegens/libcurl/lib/index.js index 255e910ca..3e16cf630 100644 --- a/codegens/libcurl/lib/index.js +++ b/codegens/libcurl/lib/index.js @@ -1,6 +1,7 @@ var sanitize = require('./util').sanitize, sanitizeOptions = require('./util').sanitizeOptions, addFormParam = require('./util').addFormParam, + getUrlStringfromUrlObject = require('./util').getUrlStringfromUrlObject, _ = require('./lodash'), self; @@ -39,7 +40,7 @@ self = module.exports = { snippet += 'if(curl) {\n'; snippet += indentString + `curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "${request.method}");\n`; snippet += indentString + - `curl_easy_setopt(curl, CURLOPT_URL, "${encodeURI(request.url.toString())}");\n`; + `curl_easy_setopt(curl, CURLOPT_URL, "${getUrlStringfromUrlObject(request.url)}");\n`; if (timeout) { snippet += indentString + `curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, ${timeout}L);\n`; } diff --git a/codegens/libcurl/lib/util.js b/codegens/libcurl/lib/util.js index 1933ea78e..ddc8cfce0 100644 --- a/codegens/libcurl/lib/util.js +++ b/codegens/libcurl/lib/util.js @@ -1,4 +1,6 @@ -module.exports = { +const _ = require('./lodash'); + +const self = module.exports = { /** * sanitizes input string by handling escape characters eg: converts '''' to '\'\'' * and trim input if required @@ -89,6 +91,90 @@ module.exports = { return result; }, + /** + * + * @param {Object} urlObject The request sdk request.url object + * @returns {String} The final string after parsing all the parameters of the url including + * protocol, auth, host, port, path, query, hash + * This will be used because the url.toString() method returned the URL with non encoded query string + * and hence a manual call is made to getQueryString() method with encode option set as true. + */ + getUrlStringfromUrlObject: function (urlObject) { + var url = ''; + if (!urlObject) { + return url; + } + if (urlObject.protocol) { + url += (urlObject.protocol.endsWith('://') ? urlObject.protocol : urlObject.protocol + '://'); + } + if (urlObject.auth && urlObject.auth.user) { + url = url + ((urlObject.auth.password) ? + urlObject.auth.user + ':' + urlObject.auth.password : urlObject.auth.user) + '@'; + } + if (urlObject.host) { + url += urlObject.getHost(); + } + if (urlObject.port) { + url += ':' + urlObject.port.toString(); + } + if (urlObject.path) { + url += urlObject.getPath(); + } + if (urlObject.query && urlObject.query.count()) { + let queryString = self.getQueryString(urlObject); + queryString && (url += '?' + queryString); + } + if (urlObject.hash) { + url += '#' + urlObject.hash; + } + + return self.sanitize(url, false); + }, + + /** + * @param {Object} urlObject + * @returns {String} + */ + getQueryString: function (urlObject) { + let isFirstParam = true, + params = _.get(urlObject, 'query.members'), + result = ''; + if (Array.isArray(params)) { + result = _.reduce(params, function (result, param) { + if (param.disabled === true) { + return result; + } + + if (isFirstParam) { + isFirstParam = false; + } + else { + result += '&'; + } + + return result + self.encodeParam(param.key) + '=' + self.encodeParam(param.value); + }, result); + } + + return result; + }, + + /** + * Encode param except the following characters- [,{,},],% + * + * @param {String} param + * @returns {String} + */ + encodeParam: function (param) { + return encodeURIComponent(param) + .replace(/%5B/g, '[') + .replace(/%7B/g, '{') + .replace(/%5D/g, ']') + .replace(/%7D/g, '}') + .replace(/%25/g, '%') + .replace(/'/g, '%27'); + }, + /** * * @param {Array} array - form data array diff --git a/codegens/nodejs-native/test/newman/newman.test.js b/codegens/nodejs-native/test/newman/newman.test.js index 77fa0174e..419b4564e 100644 --- a/codegens/nodejs-native/test/newman/newman.test.js +++ b/codegens/nodejs-native/test/newman/newman.test.js @@ -7,7 +7,8 @@ describe('Convert for different types of request', function () { headerSnippet: '/* eslint-disable */\n', compileScript: null, runScript: 'node run.js', - fileName: 'run.js' + fileName: 'run.js', + skipCollections: ['queryParamsCollection'] }; runNewmanTest(convert, options, testConfig); @@ -18,7 +19,8 @@ describe('Convert for different types of request', function () { compileScript: null, runScript: 'node run.js', fileName: 'run.js', - headerSnippet: '/* eslint-disable */\n' + headerSnippet: '/* eslint-disable */\n', + skipCollections: ['queryParamsCollection'] }; runNewmanTest(convert, options, testConfig); diff --git a/codegens/objective-c/test/newman/newman.test.js b/codegens/objective-c/test/newman/newman.test.js index efa9c568c..79119945e 100644 --- a/codegens/objective-c/test/newman/newman.test.js +++ b/codegens/objective-c/test/newman/newman.test.js @@ -8,7 +8,8 @@ describe.skip('Convert for different types of request', function () { compileScript: 'clang -framework Foundation snippet.m -o prog', runScript: './prog', fileName: 'snippet.m', - headerSnippet: '' + headerSnippet: '', + skipCollections: ['queryParamsCollection'] }; runNewmanTest(convert, options, testConfig); diff --git a/codegens/ocaml-cohttp/lib/ocaml.js b/codegens/ocaml-cohttp/lib/ocaml.js index 3eca2a4ef..93d233783 100644 --- a/codegens/ocaml-cohttp/lib/ocaml.js +++ b/codegens/ocaml-cohttp/lib/ocaml.js @@ -2,6 +2,7 @@ var _ = require('./lodash'), sanitize = require('./util').sanitize, sanitizeOptions = require('./util').sanitizeOptions, addFormParam = require('./util').addFormParam, + getUrlStringfromUrlObject = require('./util').getUrlStringfromUrlObject, self; /** @@ -313,7 +314,7 @@ self = module.exports = { // timeout = options.requestTimeout; // followRedirect = options.followRedirect; trim = options.trimRequestBody; - finalUrl = encodeURI(request.url.toString()); + finalUrl = getUrlStringfromUrlObject(request.url); methodArg = getMethodArg(request.method); if (request.body && !request.headers.has('Content-Type')) { if (request.body.mode === 'file') { diff --git a/codegens/ocaml-cohttp/lib/util.js b/codegens/ocaml-cohttp/lib/util.js index 0ca335940..7cd812e17 100644 --- a/codegens/ocaml-cohttp/lib/util.js +++ b/codegens/ocaml-cohttp/lib/util.js @@ -1,4 +1,6 @@ -module.exports = { +const _ = require('./lodash'); + +const self = module.exports = { /** * sanitization of values : trim, escape characters * @@ -102,6 +104,90 @@ module.exports = { return result; }, + /** + * + * @param {Object} urlObject The request sdk request.url object + * @returns {String} The final string after parsing all the parameters of the url including + * protocol, auth, host, port, path, query, hash + * This will be used because the url.toString() method returned the URL with non encoded query string + * and hence a manual call is made to getQueryString() method with encode option set as true. + */ + getUrlStringfromUrlObject: function (urlObject) { + var url = ''; + if (!urlObject) { + return url; + } + if (urlObject.protocol) { + url += (urlObject.protocol.endsWith('://') ? urlObject.protocol : urlObject.protocol + '://'); + } + if (urlObject.auth && urlObject.auth.user) { + url = url + ((urlObject.auth.password) ? + urlObject.auth.user + ':' + urlObject.auth.password : urlObject.auth.user) + '@'; + } + if (urlObject.host) { + url += urlObject.getHost(); + } + if (urlObject.port) { + url += ':' + urlObject.port.toString(); + } + if (urlObject.path) { + url += urlObject.getPath(); + } + if (urlObject.query && urlObject.query.count()) { + let queryString = self.getQueryString(urlObject); + queryString && (url += '?' + queryString); + } + if (urlObject.hash) { + url += '#' + urlObject.hash; + } + + return self.sanitize(url, false); + }, + + /** + * @param {Object} urlObject + * @returns {String} + */ + getQueryString: function (urlObject) { + let isFirstParam = true, + params = _.get(urlObject, 'query.members'), + result = ''; + if (Array.isArray(params)) { + result = _.reduce(params, function (result, param) { + if (param.disabled === true) { + return result; + } + + if (isFirstParam) { + isFirstParam = false; + } + else { + result += '&'; + } + + return result + self.encodeParam(param.key) + '=' + self.encodeParam(param.value); + }, result); + } + + return result; + }, + + /** + * Encode param except the following characters- [,{,},],% + * + * @param {String} param + * @returns {String} + */ + encodeParam: function (param) { + return encodeURIComponent(param) + .replace(/%5B/g, '[') + .replace(/%7B/g, '{') + .replace(/%5D/g, ']') + .replace(/%7D/g, '}') + .replace(/%25/g, '%') + .replace(/'/g, '%27'); + }, + /** * * @param {Array} array - form data array diff --git a/codegens/php-curl/lib/php-curl.js b/codegens/php-curl/lib/php-curl.js index c6a24339a..a3c82d77e 100644 --- a/codegens/php-curl/lib/php-curl.js +++ b/codegens/php-curl/lib/php-curl.js @@ -3,6 +3,7 @@ var _ = require('./lodash'), sanitize = require('./util/sanitize').sanitize, sanitizeOptions = require('./util/sanitize').sanitizeOptions, addFormParam = require('./util/sanitize').addFormParam, + getUrlStringfromUrlObject = require('./util/sanitize').getUrlStringfromUrlObject, self; /** @@ -105,11 +106,7 @@ self = module.exports = { identity = options.indentType === 'Tab' ? '\t' : ' '; indentation = identity.repeat(options.indentCount); // concatenation and making up the final string - finalUrl = request.url.toString(); - if (finalUrl !== encodeURI(finalUrl)) { - // needs to be encoded - finalUrl = encodeURI(finalUrl); - } + finalUrl = getUrlStringfromUrlObject(request.url); snippet = ' '${sanitize(finalUrl, 'url')}',\n`; diff --git a/codegens/php-curl/lib/util/sanitize.js b/codegens/php-curl/lib/util/sanitize.js index 1aa6fe271..6755abf3d 100644 --- a/codegens/php-curl/lib/util/sanitize.js +++ b/codegens/php-curl/lib/util/sanitize.js @@ -1,4 +1,6 @@ -module.exports = { +const _ = require('../lodash'); + +const self = module.exports = { /** * sanitization of values : trim, escape characters * @@ -92,6 +94,90 @@ module.exports = { return result; }, + /** + * + * @param {Object} urlObject The request sdk request.url object + * @returns {String} The final string after parsing all the parameters of the url including + * protocol, auth, host, port, path, query, hash + * This will be used because the url.toString() method returned the URL with non encoded query string + * and hence a manual call is made to getQueryString() method with encode option set as true. + */ + getUrlStringfromUrlObject: function (urlObject) { + var url = ''; + if (!urlObject) { + return url; + } + if (urlObject.protocol) { + url += (urlObject.protocol.endsWith('://') ? urlObject.protocol : urlObject.protocol + '://'); + } + if (urlObject.auth && urlObject.auth.user) { + url = url + ((urlObject.auth.password) ? + urlObject.auth.user + ':' + urlObject.auth.password : urlObject.auth.user) + '@'; + } + if (urlObject.host) { + url += urlObject.getHost(); + } + if (urlObject.port) { + url += ':' + urlObject.port.toString(); + } + if (urlObject.path) { + url += urlObject.getPath(); + } + if (urlObject.query && urlObject.query.count()) { + let queryString = self.getQueryString(urlObject); + queryString && (url += '?' + queryString); + } + if (urlObject.hash) { + url += '#' + urlObject.hash; + } + + return self.sanitize(url, false); + }, + + /** + * @param {Object} urlObject + * @returns {String} + */ + getQueryString: function (urlObject) { + let isFirstParam = true, + params = _.get(urlObject, 'query.members'), + result = ''; + if (Array.isArray(params)) { + result = _.reduce(params, function (result, param) { + if (param.disabled === true) { + return result; + } + + if (isFirstParam) { + isFirstParam = false; + } + else { + result += '&'; + } + + return result + self.encodeParam(param.key) + '=' + self.encodeParam(param.value); + }, result); + } + + return result; + }, + + /** + * Encode param except the following characters- [,{,},],% + * + * @param {String} param + * @returns {String} + */ + encodeParam: function (param) { + return encodeURIComponent(param) + .replace(/%5B/g, '[') + .replace(/%7B/g, '{') + .replace(/%5D/g, ']') + .replace(/%7D/g, '}') + .replace(/%25/g, '%') + .replace(/'/g, '%27'); + }, + /** * * @param {Array} array - form data array diff --git a/codegens/python-http.client/test/newman/newman.test.js b/codegens/python-http.client/test/newman/newman.test.js index d58bd67bf..922502fd0 100644 --- a/codegens/python-http.client/test/newman/newman.test.js +++ b/codegens/python-http.client/test/newman/newman.test.js @@ -13,7 +13,8 @@ describe('Convert for different types of request', function () { testConfig = { fileName: 'codesnippet.py', runScript: 'PYTHONIOENCODING=utf-8 python3 codesnippet.py', - skipCollections: ['redirectCollection', 'sameNameHeadersCollection', 'unsupportedMethods'] + skipCollections: ['redirectCollection', 'sameNameHeadersCollection', 'unsupportedMethods', + 'queryParamsCollection'] }; runNewmanTest(convert, options, testConfig); }); diff --git a/codegens/swift/lib/util.js b/codegens/swift/lib/util.js index dd945e811..4465a5d81 100644 --- a/codegens/swift/lib/util.js +++ b/codegens/swift/lib/util.js @@ -104,7 +104,7 @@ function sanitizeOptions (options, optionsArray) { } /** - * Encode param except the following characters- [,{,},] + * Encode param except the following characters- [,{,},],% * * @param {String} param * @returns {String} @@ -115,6 +115,7 @@ function encodeParam (param) { .replace(/%7B/g, '{') .replace(/%5D/g, ']') .replace(/%7D/g, '}') + .replace(/%25/g, '%') .replace(/'/g, '%27'); } diff --git a/codegens/swift/test/unit/convert.test.js b/codegens/swift/test/unit/convert.test.js index d5a6c50f2..ba8997124 100644 --- a/codegens/swift/test/unit/convert.test.js +++ b/codegens/swift/test/unit/convert.test.js @@ -332,6 +332,13 @@ describe('Swift Converter', function () { expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b%20c%27'); }); + it('should not encode query params that are already encoded', function () { + rawUrl = 'https://postman-echo.com/get?query=urn%3Ali%3Afoo%3A62324'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal('https://postman-echo.com/get?query=urn%3Ali%3Afoo%3A62324'); + }); + it('should discard disabled query params', function () { urlObject = new sdk.Url({ protocol: 'https', diff --git a/test/codegen/newman/fixtures/queryParamsCollection.json b/test/codegen/newman/fixtures/queryParamsCollection.json new file mode 100644 index 000000000..6420f6a29 --- /dev/null +++ b/test/codegen/newman/fixtures/queryParamsCollection.json @@ -0,0 +1,31 @@ +{ + "info": { + "_postman_id": "0bb73926-93f7-4ad4-a191-6a5d9e3460ef", + "name": "Query Params Collection", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Query Param with encoded value", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://postman-echo.com/query=urn%3Ali%3Afoo%3A62324", + "host": [ + "https://postman-echo.com" + ], + "path": [ + "get" + ], + "query": [ + { + "key": "query", + "value": "urn%3Ali%3Afoo%3A62324" + } + ] + } + } + } + ] +} \ No newline at end of file From 81a3afa8694d5aa023cf914d2db244c2adb424cd Mon Sep 17 00:00:00 2001 From: Dhwaneet Bhatt Date: Thu, 27 Apr 2023 12:01:01 +0530 Subject: [PATCH 2/3] Using GitHub Actions to automate releases --- .github/workflows/draft-new-release.yml | 78 +++++++++++++++++++ .github/workflows/publish-new-release.yml | 46 +++++++++++ .../workflows/{integration.yml => test.yml} | 0 CHANGELOG.md | 21 ++++- codegens/java-unirest/lib/parseRequest.js | 3 +- 5 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/draft-new-release.yml create mode 100644 .github/workflows/publish-new-release.yml rename .github/workflows/{integration.yml => test.yml} (100%) diff --git a/.github/workflows/draft-new-release.yml b/.github/workflows/draft-new-release.yml new file mode 100644 index 000000000..1aa067a82 --- /dev/null +++ b/.github/workflows/draft-new-release.yml @@ -0,0 +1,78 @@ +name: Draft new release + +on: + workflow_dispatch: + inputs: + version: + description: The version you want to release. Must be a valid semver version. + required: true + type: string + +jobs: + draft-new-release: + if: startsWith(github.event.inputs.version, 'v') + name: Draft a new release + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Create release branch + run: git checkout -b release/${{ github.event.inputs.version }} + + - name: Update changelog + uses: thomaseizinger/keep-a-changelog-new-release@1.1.0 + with: + version: ${{ github.event.inputs.version }} + + - name: Initialize mandatory git config + run: | + git config user.name "GitHub Actions" + git config user.email noreply@github.com + + - name: Bump version + run: npm version ${{ github.event.inputs.version }} --git-tag-version false + + - name: Commit changelog and manifest files + id: make-commit + run: | + git add CHANGELOG.md package.json package-lock.json + git commit --message "Prepare release ${{ github.event.inputs.version }}" + echo "::set-output name=commit::$(git rev-parse HEAD)" + + - name: Push new branch + run: git push origin release/${{ github.event.inputs.version }} + + - name: Create pull request for master + uses: thomaseizinger/create-pull-request@1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + head: release/${{ github.event.inputs.version }} + base: master + title: "Release version ${{ github.event.inputs.version }}" + reviewers: ${{ github.actor }} + body: | + Hi @${{ github.actor }}! + + This PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}. + I've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}. + + - name: Create pull request for develop + uses: thomaseizinger/create-pull-request@1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + head: release/${{ github.event.inputs.version }} + base: develop + title: "Release version ${{ github.event.inputs.version }}" + reviewers: ${{ github.actor }} + body: | + Hi @${{ github.actor }}! + + This PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}. + I've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}. diff --git a/.github/workflows/publish-new-release.yml b/.github/workflows/publish-new-release.yml new file mode 100644 index 000000000..7983264d7 --- /dev/null +++ b/.github/workflows/publish-new-release.yml @@ -0,0 +1,46 @@ +name: "Publish new release" + +on: + pull_request: + branches: + - master + types: + - closed + +jobs: + release: + name: Publish new release + runs-on: ubuntu-latest + # only merged pull requests that begin with 'release/' or 'hotfix/' must trigger this job + if: github.event.pull_request.merged == true && + (contains(github.event.pull_request.head.ref, 'release/') || contains(github.event.pull_request.head.ref, 'hotfix/')) + permissions: + contents: write + + steps: + - name: Extract version from branch name (for release branches) + if: contains(github.event.pull_request.head.ref, 'release/') + run: | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + VERSION=${BRANCH_NAME#release/} + + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + + - name: Extract version from branch name (for hotfix branches) + if: contains(github.event.pull_request.head.ref, 'hotfix/') + run: | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + VERSION=${BRANCH_NAME#hotfix/} + + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + + - name: Create Release + uses: thomaseizinger/create-release@1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + target_commitish: ${{ github.event.pull_request.merge_commit_sha }} + tag_name: ${{ env.RELEASE_VERSION }} + name: ${{ env.RELEASE_VERSION }} + draft: false + prerelease: false diff --git a/.github/workflows/integration.yml b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/integration.yml rename to .github/workflows/test.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bc029b3f..7104f1977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ -v1.7.1 (March 29, 2023) -* Minor fix - Add language labels for Rust and Kotlin +# Postman Code Generators Changelog + +## [Unreleased] + +### Fixed + +- Fix for - [#11934](https://github.com/postmanlabs/postman-app-support/issues/11934) Prevent `%` double encoding in query params + +## [v1.7.1] - 2023-03-29 + +- Minor fix - Add language labels for Rust and Kotlin + +## Previous Releases + +Newer releases follow the [Keep a Changelog](https://keepachangelog.com) format. v1.7.0 (March 28, 2023) * Fix for - [#192](https://github.com/postmanlabs/postman-code-generators/issues/192) Added support for Rust reqwest code snippets. @@ -101,3 +114,7 @@ v1.0.0 (May 29, 2020) - Add axios framework support - Add ES6 syntax support for NodeJS Request, NodeJS Native and NodeJS Unirest - Fix snippet generation for powershell and jquery, where form data params had no type field + +[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.7.1...HEAD + +[v1.7.1]: https://github.com/postmanlabs/postman-code-generators/compare/v1.7.0...v1.7.1 \ No newline at end of file diff --git a/codegens/java-unirest/lib/parseRequest.js b/codegens/java-unirest/lib/parseRequest.js index 8f90d59c2..6e6053bea 100644 --- a/codegens/java-unirest/lib/parseRequest.js +++ b/codegens/java-unirest/lib/parseRequest.js @@ -3,7 +3,8 @@ var _ = require('./lodash'), sanitize = require('./util').sanitize; /** - * Encode param except the following characters- [,{,},],% + * Encode param except the following characters- [,],% + * Characters { and } are kept encoded because unirest does not support them * * @param {String} param * @returns {String} From 6168e6e24f0bacd83c67314a4956d82839bfcdd7 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 4 May 2023 11:07:10 +0000 Subject: [PATCH 3/3] Prepare release v1.7.2 --- CHANGELOG.md | 153 ++++++++++++++++++++++++++-------------------- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 90 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7104f1977..4ad21d8fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +## [v1.7.2] - 2023-05-04 + ### Fixed - Fix for - [#11934](https://github.com/postmanlabs/postman-app-support/issues/11934) Prevent `%` double encoding in query params @@ -15,106 +17,127 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com) format. v1.7.0 (March 28, 2023) -* Fix for - [#192](https://github.com/postmanlabs/postman-code-generators/issues/192) Added support for Rust reqwest code snippets. + +- Fix for - [#192](https://github.com/postmanlabs/postman-code-generators/issues/192) Added support for Rust reqwest code snippets. v1.6.1 (March 27, 2023) -* Fix backlashes being unescaped unnecessarily in cURL codegen + +- Fix backlashes being unescaped unnecessarily in cURL codegen v1.6.0 (March 17, 2023) -* PEP8 improvements in python-requests code -* Fix for - [#491](https://github.com/postmanlabs/postman-code-generators/issues/491) Added support for kotlin okhttp code snippets. -* Refactored code for nodejs-axios util.js. + +- PEP8 improvements in python-requests code +- Fix for - [#491](https://github.com/postmanlabs/postman-code-generators/issues/491) Added support for kotlin okhttp code snippets. +- Refactored code for nodejs-axios util.js. v1.5.1 (March 28, 2023) -* Fix backlashes being escaped unnecessarily in cURL codegen + +- Fix backlashes being escaped unnecessarily in cURL codegen v1.5.0 (March 2, 2023) -* Change minimum supported NodeJS version to 12 -* Fix for - [#11049](https://github.com/postmanlabs/postman-app-support/issues/11049) Escape backslash character in raw bodies for curl codegen -* Fix for - [#302](https://github.com/postmanlabs/postman-code-generators/issues/302) Add option to use async/await in NodeJS Axios codegen -* Fix for - [#322](https://github.com/postmanlabs/postman-code-generators/issues/322) Use multiline quotes in Powershell to simplify generated code -* Add long form option for -g flag in curl codegen -* Minor Swift codegen improvements + +- Change minimum supported NodeJS version to 12 +- Fix for - [#11049](https://github.com/postmanlabs/postman-app-support/issues/11049) Escape backslash character in raw bodies for curl codegen +- Fix for - [#302](https://github.com/postmanlabs/postman-code-generators/issues/302) Add option to use async/await in NodeJS Axios codegen +- Fix for - [#322](https://github.com/postmanlabs/postman-code-generators/issues/322) Use multiline quotes in Powershell to simplify generated code +- Add long form option for -g flag in curl codegen +- Minor Swift codegen improvements v1.4.1 (February 22, 2023) -* cURL codegen should work when request has a protocolProfileBehavior with null value + +- cURL codegen should work when request has a protocolProfileBehavior with null value v1.4.0 (February 6, 2023) -* Add support for C# HttpClient Codegen -* Fix for - [#9511](https://github.com/postmanlabs/postman-app-support/issues/9511) - Use short options in CURL as long as possible -* Fix for - [#10581](https://github.com/postmanlabs/postman-app-support/issues/10581) - Do not add HTTP method explicitly in CURL when not required -* Fix for - [#10053](https://github.com/postmanlabs/postman-app-support/issues/10053) - Remove usage of semaphore from Swift Codegen + +- Add support for C# HttpClient Codegen +- Fix for - [#9511](https://github.com/postmanlabs/postman-app-support/issues/9511) - Use short options in CURL as long as possible +- Fix for - [#10581](https://github.com/postmanlabs/postman-app-support/issues/10581) - Do not add HTTP method explicitly in CURL when not required +- Fix for - [#10053](https://github.com/postmanlabs/postman-app-support/issues/10053) - Remove usage of semaphore from Swift Codegen v1.3.0 (December 16, 2022) -* Update C# restsharp codegen to support [107](https://restsharp.dev/v107/) -* Fix for - [#11084](https://github.com/postmanlabs/postman-app-support/issues/11084) Fixes an issue where HTTP code snippet was generating wrong boundaries -* Fixes an issue with Axios code snippets not including maxBodyLength param + +- Update C# restsharp codegen to support [107](https://restsharp.dev/v107/) +- Fix for - [#11084](https://github.com/postmanlabs/postman-app-support/issues/11084) Fixes an issue where HTTP code snippet was generating wrong boundaries +- Fixes an issue with Axios code snippets not including maxBodyLength param v1.2.1 (April 26, 2022) -* Add label for 'R' language + +- Add label for 'R' language v1.2.0 (April 22, 2022) -* Add new codegens - php-guzzle, R-httr, R-rcurl -* Fix issue with pipeline failing due to updated version of RestSharp -* Fix for - [#502](https://github.com/postmanlabs/postman-code-generators/issues/502) Allow GET method to have a body in java-okhttp if present in input request -* Fix for - [#476](https://github.com/postmanlabs/postman-code-generators/pull/476) Properly escape already escaped double quotes in curl body + +- Add new codegens - php-guzzle, R-httr, R-rcurl +- Fix issue with pipeline failing due to updated version of RestSharp +- Fix for - [#502](https://github.com/postmanlabs/postman-code-generators/issues/502) Allow GET method to have a body in java-okhttp if present in input request +- Fix for - [#476](https://github.com/postmanlabs/postman-code-generators/pull/476) Properly escape already escaped double quotes in curl body v1.1.5 (May 10, 2021) -* Fixed an issue with how JSON bodies are shown in code snippets for Ruby, C#, and Dart. + +- Fixed an issue with how JSON bodies are shown in code snippets for Ruby, C#, and Dart. v1.1.4 (May 6, 2021) -* Fix an issue with empty GraphQL body + +- Fix an issue with empty GraphQL body v1.1.3 (Mar 2, 2021) -* Use proper indentation for JSON bodies in Javascript and Nodejs codegens -* Fix for - [#445](https://github.com/postmanlabs/postman-code-generators/issues/445) Add proper indentation in nodejs-axios when bodytype is urlencoded -* Fix for - [#248](https://github.com/postmanlabs/postman-code-generators/issues/248) Use quoteType everywhere in curl, not just in the url -* Fix for - [#454](https://github.com/postmanlabs/postman-code-generators/issues/454) Fix encoding when generating HTTP code snippets -* Fix for - [#426](https://github.com/postmanlabs/postman-code-generators/issues/426) Use json.dumps in Python codegens if Content-Type is JSON + +- Use proper indentation for JSON bodies in Javascript and Nodejs codegens +- Fix for - [#445](https://github.com/postmanlabs/postman-code-generators/issues/445) Add proper indentation in nodejs-axios when bodytype is urlencoded +- Fix for - [#248](https://github.com/postmanlabs/postman-code-generators/issues/248) Use quoteType everywhere in curl, not just in the url +- Fix for - [#454](https://github.com/postmanlabs/postman-code-generators/issues/454) Fix encoding when generating HTTP code snippets +- Fix for - [#426](https://github.com/postmanlabs/postman-code-generators/issues/426) Use json.dumps in Python codegens if Content-Type is JSON v1.1.2 (Dec 15, 2020) -* Fix for - [#8736](https://github.com/postmanlabs/postman-app-support/issues/8736) Add content type support for individual form-data fields -* Fix for - [#8635](https://github.com/postmanlabs/postman-app-support/issues/8635) Use Json.parse for all json like application types -* Fix for - [#9212](https://github.com/postmanlabs/postman-app-support/issues/9212) Add semicolon after header key in curl codegen if the value is empty string. -* Add Newman test for powershell + +- Fix for - [#8736](https://github.com/postmanlabs/postman-app-support/issues/8736) Add content type support for individual form-data fields +- Fix for - [#8635](https://github.com/postmanlabs/postman-app-support/issues/8635) Use Json.parse for all json like application types +- Fix for - [#9212](https://github.com/postmanlabs/postman-app-support/issues/9212) Add semicolon after header key in curl codegen if the value is empty string. +- Add Newman test for powershell v1.1.1 (Nov 10, 2020) -* Change string to enum in cURL quoteType option. -* Fix new line issue in dart-http and HTTP codegen -* Fix an issue where deepinstall was failing when folder name had spaces. + +- Change string to enum in cURL quoteType option. +- Fix new line issue in dart-http and HTTP codegen +- Fix an issue where deepinstall was failing when folder name had spaces. v1.1.0 (Nov 2, 2020) -* Added support for Dart http -* Fix for - [#315](https://github.com/postmanlabs/postman-code-generators/issues/315): Manually parse url provided in the request. -* Fix for - [#253](https://github.com/postmanlabs/postman-code-generators/issues/253): Add -g flag to curl if braces ({}) or brackets ([#]) are present in the url. -* Fix for - [#257](https://github.com/postmanlabs/postman-code-generators/issues/257): Use double quotes to escape semicolon in curl requests -* Fix for - [#247](https://github.com/postmanlabs/postman-code-generators/issues/247): Add ContentType to python snippets for multipart/formdata -* Fix for - [#186](https://github.com/postmanlabs/postman-code-generators/issues/186): Add ` as line continuation delimiter for curl codegen -* Fix for - [#248](https://github.com/postmanlabs/postman-code-generators/issues/248): Add quoteType as an additional option in curl codegen -* Fix deadlock in error case in Swift and Objective-C codegens. -* Fix for - [#325](https://github.com/postmanlabs/postman-code-generators/issues/325): Use encodeURIComponent instead of escape for urlencoded request body. -* Fix for - [#350](https://github.com/postmanlabs/postman-code-generators/issues/350): Sanitize \r in request body. -* Fix for - [#366](https://github.com/postmanlabs/postman-code-generators/issues/366): Add support for uploading binary files for multipart/form-data bodies in python-http.client. -* Fix for - [#353](https://github.com/postmanlabs/postman-code-generators/issues/353): Add optional import of FoundationNetworking in swift codegen -* Fix for - [#284](https://github.com/postmanlabs/postman-code-generators/issues/284): Replace double-quotes by single-quotes in codegen/php-curl -* Fix for - [#330](https://github.com/postmanlabs/postman-code-generators/issues/330): Use url.toString method for converting url in shell-httpie codegen + +- Added support for Dart http +- Fix for - [#315](https://github.com/postmanlabs/postman-code-generators/issues/315): Manually parse url provided in the request. +- Fix for - [#253](https://github.com/postmanlabs/postman-code-generators/issues/253): Add -g flag to curl if braces ({}) or brackets ([#]) are present in the url. +- Fix for - [#257](https://github.com/postmanlabs/postman-code-generators/issues/257): Use double quotes to escape semicolon in curl requests +- Fix for - [#247](https://github.com/postmanlabs/postman-code-generators/issues/247): Add ContentType to python snippets for multipart/formdata +- Fix for - [#186](https://github.com/postmanlabs/postman-code-generators/issues/186): Add \` as line continuation delimiter for curl codegen +- Fix for - [#248](https://github.com/postmanlabs/postman-code-generators/issues/248): Add quoteType as an additional option in curl codegen +- Fix deadlock in error case in Swift and Objective-C codegens. +- Fix for - [#325](https://github.com/postmanlabs/postman-code-generators/issues/325): Use encodeURIComponent instead of escape for urlencoded request body. +- Fix for - [#350](https://github.com/postmanlabs/postman-code-generators/issues/350): Sanitize \\r in request body. +- Fix for - [#366](https://github.com/postmanlabs/postman-code-generators/issues/366): Add support for uploading binary files for multipart/form-data bodies in python-http.client. +- Fix for - [#353](https://github.com/postmanlabs/postman-code-generators/issues/353): Add optional import of FoundationNetworking in swift codegen +- Fix for - [#284](https://github.com/postmanlabs/postman-code-generators/issues/284): Replace double-quotes by single-quotes in codegen/php-curl +- Fix for - [#330](https://github.com/postmanlabs/postman-code-generators/issues/330): Use url.toString method for converting url in shell-httpie codegen v1.0.2 (Oct 15, 2020) -* Fixed spaces around variables and arguments in Python codgen to comply with PEP 8. -* Added Content-Length header to generated HTTP snippets. -* Switched to multiline strings for Raw bodies in Go. -* Stopped manually encoding response bodes in `utf8` for Python-requests. -* Removed unnecessary semicolons at the end of statements in Ruby. -* Fixed wrong name of HTTP codegen in README + +- Fixed spaces around variables and arguments in Python codgen to comply with PEP 8. +- Added Content-Length header to generated HTTP snippets. +- Switched to multiline strings for Raw bodies in Go. +- Stopped manually encoding response bodes in `utf8` for Python-requests. +- Removed unnecessary semicolons at the end of statements in Ruby. +- Fixed wrong name of HTTP codegen in README v1.0.1 (Jun 29, 2020) -- Fix for - [#8674](https://github.com/postmanlabs/postman-app-support/issues/8674): Add URL sanitization for quotes in cURL, Java Unirest, NodeJS Native, Python http.client, and Swift. + +- Fix for - [#8674](https://github.com/postmanlabs/postman-app-support/issues/8674): Add URL sanitization for quotes in cURL, Java Unirest, NodeJS Native, Python http.client, and Swift. v1.0.0 (May 29, 2020) -- Add axios framework support -- Add ES6 syntax support for NodeJS Request, NodeJS Native and NodeJS Unirest -- Fix snippet generation for powershell and jquery, where form data params had no type field -[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.7.1...HEAD +- Add axios framework support +- Add ES6 syntax support for NodeJS Request, NodeJS Native and NodeJS Unirest +- Fix snippet generation for powershell and jquery, where form data params had no type field + +[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.7.2...HEAD + +[v1.7.2]: https://github.com/postmanlabs/postman-code-generators/compare/v1.7.1...v1.7.2 -[v1.7.1]: https://github.com/postmanlabs/postman-code-generators/compare/v1.7.0...v1.7.1 \ No newline at end of file +[v1.7.1]: https://github.com/postmanlabs/postman-code-generators/compare/v1.7.0...v1.7.1 diff --git a/package-lock.json b/package-lock.json index 39d8ad364..05b9e9d06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "postman-code-generators", - "version": "1.7.1", + "version": "1.7.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 750ff1db6..465fe332f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postman-code-generators", - "version": "1.7.1", + "version": "1.7.2", "description": "Generates code snippets for a postman collection", "main": "index.js", "directories": {