mirror of
https://github.com/Kong/insomnia.git
synced 2026-05-18 21:55:38 -04:00
Only handle supported Curl args during import (Fixes #1697)
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
curl --compressed 'https://www.google.com/'
|
||||
@@ -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": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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}=`, '');
|
||||
|
||||
Reference in New Issue
Block a user