Skip to content

Commit

Permalink
Merge pull request #81 from postmanlabs/release/v1.8.1
Browse files Browse the repository at this point in the history
Release version v1.8.1
  • Loading branch information
VShingala authored Apr 17, 2024
2 parents 775430d + 30424c2 commit 6d6a626
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
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 @@ const commander = require('commander'),
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 @@ var program,
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 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

0 comments on commit 6d6a626

Please sign in to comment.