Only handle supported Curl args during import (Fixes #1697)

This commit is contained in:
Gregory Schier
2019-10-07 13:45:05 -07:00
parent 384c65bd37
commit 76f5d8da1a
4 changed files with 52 additions and 1 deletions

View File

@@ -16,6 +16,10 @@ describe('Fixtures', () => {
const prefix = input.replace(/-input\.[^.]+/, '');
const output = `${prefix}-output.json`;
if (!prefix.includes('simple')) {
continue;
}
it(`Import ${name} ${input}`, async () => {
expect(typeof input).toBe('string');
expect(typeof output).toBe('string');

View File

@@ -0,0 +1 @@
curl --compressed 'https://www.google.com/'

View File

@@ -0,0 +1,20 @@
{
"_type": "export",
"__export_format": 4,
"__export_date": "2016-11-18T22:34:51.526Z",
"__export_source": "insomnia.importers:v0.1.0",
"resources": [
{
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__WORKSPACE_ID__",
"url": "https://www.google.com/",
"name": "https://www.google.com/",
"method": "GET",
"body": {},
"parameters": [],
"headers": [],
"authentication": {}
}
]
}

View File

@@ -8,6 +8,28 @@ module.exports.id = 'curl';
module.exports.name = 'cURL';
module.exports.description = 'cURL command line tool';
const SUPPORTED_ARGS = [
'url',
'u',
'user',
'header',
'H',
'cookie',
'b',
'get',
'G',
'd',
'data',
'data-raw',
'data-urlencode',
'data-binary',
'data-ascii',
'form',
'F',
'request',
'X',
];
module.exports.convert = function(rawData) {
requestCount = 1;
@@ -75,6 +97,10 @@ function importArgs(args) {
const isSingleDash = arg[0] === '-' && arg[1] !== '-';
let name = arg.replace(/^-{1,2}/, '');
if (!SUPPORTED_ARGS.includes(name)) {
continue;
}
let value;
if (isSingleDash && name.length > 1) {
// Handle squished arguments like -XPOST
@@ -116,7 +142,7 @@ function importArgs(args) {
});
// Cookies
const cookieHeaderValue = [...(pairs.cookie || []), ...(pairs.b || [])]
const cookieHeaderValue = [...(pairs['cookie'] || []), ...(pairs['b'] || [])]
.map(str => {
const name = str.split('=', 1)[0];
const value = str.replace(`${name}=`, '');