curl-to-postmanv2
Advanced tools
Comparing version 1.5.0 to 1.6.0
106
CHANGELOG.md
# cURL to Postman Importer Changelog | ||
#### v1.5.0 (March 31, 2023) | ||
* Fixed an issue where request generation failed for certain bash operators. | ||
* Fixed an issue where cURL with comments described was converted incorrectly. | ||
## [Unreleased] | ||
## [v1.6.0] - 2023-04-17 | ||
### Added | ||
- Add url validation in validate and convert functions | ||
- GitHub Actions for Release management. | ||
### Changed | ||
- Bumped up minimum Node version to 12. | ||
- Unit tests now run on Node versions 12, 16 and 18. | ||
## [v1.5.0] - 2023-03-31 | ||
- Fixed an issue where request generation failed for certain bash operators. | ||
- Fixed an issue where cURL with comments described was converted incorrectly. | ||
## Previous Releases | ||
Newer releases follow the [Keep a Changelog](https://keepachangelog.com) format. | ||
#### v1.4.0 (March 17, 2023) | ||
* Fixed issue [#7895](https://github.com/postmanlabs/postman-app-support/issues/7895) where cURL with no specific method defined for formdata type of body were not converted correctly. | ||
- Fixed issue [#7895](https://github.com/postmanlabs/postman-app-support/issues/7895) where cURL with no specific method defined for formdata type of body were not converted correctly. | ||
#### v1.3.0 (March 02, 2023) | ||
* Fix for [#8087](https://github.com/postmanlabs/postman-app-support/issues/8087) - Add support to convert digest and NTLM auth types | ||
- Fix for [#8087](https://github.com/postmanlabs/postman-app-support/issues/8087) - Add support to convert digest and NTLM auth types | ||
#### v1.2.0 (February 07, 2023) | ||
* Fix an issue where a correct error is thrown if curl string has invalid args | ||
- Fix an issue where a correct error is thrown if curl string has invalid args | ||
#### v1.1.3 (February 03, 2023) | ||
* Fixed issue [#5182](https://github.com/postmanlabs/postman-app-support/issues/5182) where cURL in Windows cmd formats were not imported correctly. | ||
- Fixed issue [#5182](https://github.com/postmanlabs/postman-app-support/issues/5182) where cURL in Windows cmd formats were not imported correctly. | ||
#### v1.1.2 (January 10, 2023) | ||
* Changed regex to check for prefix space in url with query parameters for given curl string | ||
- Changed regex to check for prefix space in url with query parameters for given curl string | ||
#### v1.1.1 (June 2, 2022) | ||
* Updated how error was handled in case of malformed URL. | ||
- Updated how error was handled in case of malformed URL. | ||
#### v1.1.0 (May 16, 2022) | ||
* Fixes #8433 - non-apostrophed ('...') url with multiple params support in cURL import. | ||
- Fixes #8433 - non-apostrophed ('...') url with multiple params support in cURL import. | ||
#### v1.0.0 (October 18, 2021) | ||
* Fixed issue where file references were not present in imported cURL.◊ | ||
* Fixed issue where formdata value were not un-escaped correctly. | ||
* Fixed issue where raw formdata string with boundary were not converted as formdata body. | ||
* Fixed issue where escaped single character sequence were not correctly represented in request body. | ||
* Fixed issue where some characters were not escaped correctly. | ||
* Updated README with installation and use cases and added LICENSE. | ||
* Added script for automating release process. | ||
- Fixed issue where file references were not present in imported cURL.◊ | ||
- Fixed issue where formdata value were not un-escaped correctly. | ||
- Fixed issue where raw formdata string with boundary were not converted as formdata body. | ||
- Fixed issue where escaped single character sequence were not correctly represented in request body. | ||
- Fixed issue where some characters were not escaped correctly. | ||
- Updated README with installation and use cases and added LICENSE. | ||
- Added script for automating release process. | ||
#### 0.5.1: Apr 29, 2020 | ||
* Added getMetaData function in root exports | ||
- Added getMetaData function in root exports | ||
#### 0.5.0: Apr 29, 2020 | ||
* Added a function to get meta data from a curl command. | ||
- Added a function to get meta data from a curl command. | ||
#### 0.4.0: Apr 21, 2020 | ||
* Fix for https://github.com/postmanlabs/postman-app-support/issues/8292 - --data-urlencode now successfully imports body | ||
- Fix for <https://github.com/postmanlabs/postman-app-support/issues/8292> - --data-urlencode now successfully imports body | ||
#### 0.3.0: Mar 27, 2020 | ||
* Fix for https://github.com/postmanlabs/postman-app-support/issues/7806 - -X argument parses method correcrtly, not interfere with any other args | ||
- Fix for <https://github.com/postmanlabs/postman-app-support/issues/7806> - -X argument parses method correcrtly, not interfere with any other args | ||
#### 0.2.0: Mar 11, 2020 | ||
* Fix for https://github.com/postmanlabs/postman-app-support/issues/7895 - --data-raw now successfully imports body | ||
- Fix for <https://github.com/postmanlabs/postman-app-support/issues/7895> - --data-raw now successfully imports body | ||
#### 0.1.0: Nov 22, 2019 | ||
* Fix for https://github.com/postmanlabs/postman-app-support/issues/2791 - not escaping single quotes correctly in the cURL commands | ||
* Fix for https://github.com/postmanlabs/postman-app-support/issues/7390 - removing unnecessary options from the cURL commands | ||
- Fix for <https://github.com/postmanlabs/postman-app-support/issues/2791> - not escaping single quotes correctly in the cURL commands | ||
- Fix for <https://github.com/postmanlabs/postman-app-support/issues/7390> - removing unnecessary options from the cURL commands | ||
#### 0.0.5: Sep 3, 2019 | ||
* Fix for https://github.com/postmanlabs/curl-to-postman/issues/1 - cURL commands with `$` prepended to arguments not importing correctly | ||
* Fix for https://github.com/postmanlabs/curl-to-postman/issues/2 - the importer was using -X to determine method, not -d or --head | ||
* Fix for https://github.com/postmanlabs/curl-to-postman/issues/4 - Data parameters are added to the URL if the method is determined to be GET, PUT, or HEAD | ||
- Fix for <https://github.com/postmanlabs/curl-to-postman/issues/1> - cURL commands with `$` prepended to arguments not importing correctly | ||
- Fix for <https://github.com/postmanlabs/curl-to-postman/issues/2> - the importer was using -X to determine method, not -d or --head | ||
- Fix for <https://github.com/postmanlabs/curl-to-postman/issues/4> - Data parameters are added to the URL if the method is determined to be GET, PUT, or HEAD | ||
#### 0.0.4: June 5, 2019 | ||
* Updated dependency versions | ||
* Updated lockfile for npm@6.4.1 | ||
- Updated dependency versions | ||
- Updated lockfile for npm@6.4.1 | ||
#### 0.0.3: May 29, 2019 | ||
* First public (beta) release | ||
* Conforming to the internal Postman plugin interface | ||
* Fixes for Github issues - 4770,3623,3135,4018,5737,5286, among others | ||
- First public (beta) release | ||
- Conforming to the internal Postman plugin interface | ||
- Fixes for Github issues - 4770,3623,3135,4018,5737,5286, among others | ||
[Unreleased]: https://github.com/postmanlabs/curl-to-postman/compare/v1.6.0...HEAD | ||
[v1.6.0]: https://github.com/postmanlabs/curl-to-postman/compare/v1.5.0...v1.6.0 | ||
[v1.5.0]: https://github.com/postmanlabs/curl-to-postman/compare/1.4.0...1.5.0 |
{ | ||
"name": "curl-to-postmanv2", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Convert a given CURL command to a Postman request", | ||
@@ -11,2 +11,5 @@ "main": "index.js", | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"dependencies": { | ||
@@ -16,3 +19,4 @@ "commander": "2.20.3", | ||
"shell-quote": "1.6.1", | ||
"uuid": "3.2.1" | ||
"uuid": "3.2.1", | ||
"valid-url": "^1.0.9" | ||
}, | ||
@@ -19,0 +23,0 @@ "devDependencies": { |
131
src/lib.js
const commander = require('commander'), | ||
validUrl = require('valid-url'), | ||
_ = require('lodash').noConflict(), | ||
@@ -122,3 +123,3 @@ shellQuote = require('../assets/shell-quote'), | ||
curlObj.head && !curlObj.get) { | ||
throw new Error('Error while parsing cURL: Both (--head/-I) and' + | ||
throw new Error('Unable to parse: Both (--head/-I) and' + | ||
' (-d/--data/--data-raw/--data-binary/--data-ascii/--data-urlencode) are not supported'); | ||
@@ -442,3 +443,3 @@ } | ||
/* eslint-disable max-depth */ | ||
if (this.requestUrl.startsWith('-')) { | ||
if (!validUrl.isUri(this.requestUrl)) { | ||
// eslint-disable-next-line no-throw-literal | ||
@@ -449,3 +450,3 @@ throw 'No valid URL found'; | ||
catch (e) { | ||
throw new Error('Error while parsing cURL: Could not identify the URL. Please use the --url option.'); | ||
throw new Error('Unable to parse: Could not identify the URL. Please use the --url option.'); | ||
} | ||
@@ -598,2 +599,79 @@ } | ||
/** | ||
* Sanitise and parse the input cURl string | ||
* | ||
* @param {string} curlString - Input cURL string | ||
* @returns {object} - Parsed cURL Object | ||
*/ | ||
getCurlObject: function (curlString) { | ||
let cleanedCurlString = curlString, | ||
sanitizedArgs, | ||
isMethodGuessed = false, | ||
curlObj; | ||
try { | ||
sanitizedArgs = this.sanitizeArgs(cleanedCurlString); | ||
curlObj = program.parse(sanitizedArgs); | ||
} | ||
catch (e) { | ||
// [Github #8843] - RegEx to fix malformed cURLs with unquoted multi-param URLs | ||
const multiParamUrlRegEx = /\s([^'` "\n]+)\.([^ \n]+)&((?!["'])[^ "`'\n])+($|(?=\s))/gm; | ||
let matchedStrings = curlString.match(multiParamUrlRegEx), | ||
matchedString = '', | ||
prefixString = ''; | ||
if (matchedStrings && matchedStrings.length > 0) { | ||
prefixString = matchedStrings[0].slice(0, 1); | ||
matchedString = matchedStrings[0].slice(1); | ||
} | ||
cleanedCurlString = curlString.replace(multiParamUrlRegEx, `${prefixString}'${matchedString}'`); | ||
sanitizedArgs = this.sanitizeArgs(cleanedCurlString); | ||
curlObj = program.parse(sanitizedArgs); | ||
} | ||
// Filter out comments from Args | ||
curlObj.args = _.filter(curlObj.args, (arg) => { | ||
// Each arg should be string itself, for comment we receive an object from parser | ||
return !(typeof arg === 'object' && typeof arg.comment === 'string'); | ||
}); | ||
this.headerPairs = {}; | ||
// if method is not given in the curl command | ||
if (!curlObj.request) { | ||
curlObj.request = this.getRequestMethod(curlObj); | ||
isMethodGuessed = true; | ||
} | ||
curlObj.request = this.trimQuotesFromString(curlObj.request); | ||
this.validateCurlRequest(curlObj); | ||
this.getRequestUrl(curlObj); | ||
return { isMethodGuessed, curlObj }; | ||
}, | ||
/** | ||
* Valid if the input cURL string is valid or not | ||
* | ||
* @param {string} curlString - Input cURL string | ||
* @param {boolean} shouldRetry - Whether we should retry parsing for Windows CMD style cURL input | ||
* @returns {Object} - { result: true } if cURL is valid otherwise { result: false } with reason | ||
*/ | ||
validate: function (curlString, shouldRetry = true) { | ||
try { | ||
this.initialize(); | ||
this.getCurlObject(curlString); | ||
return { result: true }; | ||
} | ||
catch (e) { | ||
if (shouldRetry) { | ||
curlString = this.transformCmdToBash(curlString); | ||
return this.validate(curlString, false); | ||
} | ||
return { result: false, reason: e.message }; | ||
} | ||
}, | ||
convertCurlToRequest: function(curlString, shouldRetry = true) { | ||
@@ -604,5 +682,3 @@ try { | ||
var cleanedCurlString = curlString, | ||
sanitizedArgs, | ||
curlObj, | ||
let { isMethodGuessed, curlObj } = this.getCurlObject(curlString), | ||
request = {}, | ||
@@ -616,45 +692,4 @@ content_type, | ||
dataUrlencode, | ||
formData, | ||
isMethodGuessed = false; | ||
formData; | ||
try { | ||
sanitizedArgs = this.sanitizeArgs(cleanedCurlString); | ||
curlObj = program.parse(sanitizedArgs); | ||
} | ||
catch (e) { | ||
// [Github #8843] - RegEx to fix malformed cURLs with unquoted multi-param URLs | ||
const multiParamUrlRegEx = /\s([^'` "\n]+)\.([^ \n]+)&((?!["'])[^ "`'\n])+($|(?=\s))/gm; | ||
let matchedStrings = curlString.match(multiParamUrlRegEx), | ||
matchedString = '', | ||
prefixString = ''; | ||
if (matchedStrings && matchedStrings.length > 0) { | ||
prefixString = matchedStrings[0].slice(0, 1); | ||
matchedString = matchedStrings[0].slice(1); | ||
} | ||
cleanedCurlString = curlString.replace(multiParamUrlRegEx, `${prefixString}'${matchedString}'`); | ||
sanitizedArgs = this.sanitizeArgs(cleanedCurlString); | ||
curlObj = program.parse(sanitizedArgs); | ||
} | ||
// Filter out comments from Args | ||
curlObj.args = _.filter(curlObj.args, (arg) => { | ||
// Each arg should be string itself, for comment we receive an object from parser | ||
return !(typeof arg === 'object' && typeof arg.comment === 'string'); | ||
}); | ||
this.headerPairs = {}; | ||
// if method is not given in the curl command | ||
if (!curlObj.request) { | ||
curlObj.request = this.getRequestMethod(curlObj); | ||
isMethodGuessed = true; | ||
} | ||
curlObj.request = this.trimQuotesFromString(curlObj.request); | ||
this.validateCurlRequest(curlObj); | ||
this.getRequestUrl(curlObj); | ||
request.method = 'GET'; | ||
@@ -661,0 +696,0 @@ if (curlObj.request && curlObj.request.length !== 0) { |
@@ -0,1 +1,2 @@ | ||
var lib = require('./lib.js'); | ||
module.exports = function (curlCommand) { | ||
@@ -7,5 +8,3 @@ // must be a string that starts with "curl " | ||
) { | ||
return { | ||
result: true | ||
}; | ||
return lib.validate(curlCommand); | ||
} | ||
@@ -12,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80175
22
1275
5
+ Addedvalid-url@^1.0.9
+ Addedvalid-url@1.0.9(transitive)