Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version v1.8.1 #81

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [v1.8.1] - 2024-04-17

### Added

- Added support for determining raw body language based on content-type header.

## [v1.8.0] - 2024-01-17

### Changed
Expand Down Expand Up @@ -122,7 +128,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com) format.
- 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.8.0...HEAD
[Unreleased]: https://github.com/postmanlabs/curl-to-postman/compare/v1.8.1...HEAD

[v1.8.1]: https://github.com/postmanlabs/curl-to-postman/compare/v1.8.0...v1.8.1

[v1.8.0]: https://github.com/postmanlabs/curl-to-postman/compare/v1.7.1...v1.8.0

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "curl-to-postmanv2",
"version": "1.8.0",
"version": "1.8.1",
"description": "Convert a given CURL command to a Postman request",
"main": "index.js",
"com_postman_plugin": {
Expand Down
29 changes: 28 additions & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
UserError = require('./UserError'),
{ USER_ERRORS } = require('./constants'),
formDataOptions = ['-d', '--data', '--data-raw', '--data-binary', '--data-ascii'],
allowedOperators = ['<', '>', '(', ')'];
allowedOperators = ['<', '>', '(', ')'],
REQUEST_BODY_LANGUAGE_TEXT = 'text',
REQUEST_BODY_LANGUAGE_JSON = 'json',
REQUEST_BODY_LANGUAGE_JAVASCRIPT = 'javascript',
REQUEST_BODY_LANGUAGE_HTML = 'html',
REQUEST_BODY_LANGUAGE_XML = 'xml',
LANGUAGE_REGEX_MATCH = {
[REQUEST_BODY_LANGUAGE_JSON]: /^application\/(\S+\+)?json/,
[REQUEST_BODY_LANGUAGE_JAVASCRIPT]: /^(text|application)\/(\S+\+)?javascript/,
[REQUEST_BODY_LANGUAGE_XML]: /^(text|application)\/(\S+\+)?xml/,
[REQUEST_BODY_LANGUAGE_HTML]: /^text\/html/
};

var program,

Expand Down Expand Up @@ -838,6 +849,22 @@
else {
request.body.mode = 'raw';
request.body.raw = rawDataString;

request.body.options = {};
request.body.options.raw = {};

/* eslint-disable max-depth */
try {
request.body.options.raw.language = Object.keys(LANGUAGE_REGEX_MATCH)
.find((key) => {
return LANGUAGE_REGEX_MATCH[key].test(content_type);
}) || REQUEST_BODY_LANGUAGE_TEXT;
}
catch (err) {
// In case of error, set language to text as default
request.body.options.raw.language = REQUEST_BODY_LANGUAGE_TEXT;
}
/* eslint-enable max-depth */
}

urlData = request.data;
Expand All @@ -848,7 +875,7 @@
* get data arg value from raw args as formdata boundary separated string
* is not parsed as any of data options by commander
*/
_.forEach(curlObj.rawArgs, (arg, index) => {

Check warning on line 878 in src/lib.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (12.x)

Expected to return a value at the end of arrow function

Check warning on line 878 in src/lib.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Expected to return a value at the end of arrow function

Check warning on line 878 in src/lib.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (12.x)

Expected to return a value at the end of arrow function

Check warning on line 878 in src/lib.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Expected to return a value at the end of arrow function

Check warning on line 878 in src/lib.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Expected to return a value at the end of arrow function

Check warning on line 878 in src/lib.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Expected to return a value at the end of arrow function
if (_.includes(formDataOptions, arg)) {
formData = _.get(curlObj.rawArgs, index + 1);
return false;
Expand Down
26 changes: 26 additions & 0 deletions test/conversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,32 @@ describe('Curl converter should', function() {
done();
});

it('should convert a POST request and assign json language using content-type header', function(done) {
var result = Converter.convertCurlToRequest(`curl -X POST -H "Content-Type: application/json" \\
-d \'{"key":"value"}\' https://www.example.com`);

expect(result.body).to.eql({
mode: 'raw',
raw: '{"key":"value"}',
options: { raw: { language: 'json' } }
});

done();
});

it('should convert a POST request and assign xml language using content-type header', function(done) {
var result = Converter.convertCurlToRequest(`curl -X POST -H "Content-Type: application/xml" \\
-d \'<root><key>value</key></root>\' https://www.example.com`);

expect(result.body).to.eql({
mode: 'raw',
raw: '<root><key>value</key></root>',
options: { raw: { language: 'xml' } }
});

done();
});

describe('[Github #8843]: It should recognize non-apostrophed ("...") url with multi-param', function() {
it('in case where there is multiple params with & in between in the url (https)', function(done) {
convert({
Expand Down
Loading