mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
* fix: multi-line curl not properly imported due to padding #6755 * Update curl.test.ts * Update curl.test.ts
This commit is contained in:
parent
5586d4819f
commit
ee5d346fcf
@ -153,4 +153,23 @@ describe('curl', () => {
|
||||
}]);
|
||||
});
|
||||
});
|
||||
describe('cURL -H flags', () => {
|
||||
it.each([
|
||||
{ flag: '-H', inputs: ['X-Host: example.com'], expected: [{ name: 'X-Host', value: 'example.com' }] },
|
||||
{ flag: '-H', inputs: ['X-Host:example.com'], expected: [{ name: 'X-Host', value: 'example.com' }] },
|
||||
{ flag: '-H', inputs: ['Content-Type:application/x-www-form-urlencoded'], expected: [{ name: 'Content-Type', value: 'application/x-www-form-urlencoded' }] },
|
||||
{ flag: ' -H', inputs: ['Content-Type:application/x-www-form-urlencoded'], expected: [{ name: 'Content-Type', value: 'application/x-www-form-urlencoded' }] },
|
||||
{ flag: ' -H', inputs: ['Content-Type:application/x-www-form-urlencoded'], expected: [{ name: 'Content-Type', value: 'application/x-www-form-urlencoded' }] },
|
||||
])('handles %p correctly', async ({
|
||||
flag,
|
||||
inputs,
|
||||
expected,
|
||||
}: { flag: string; inputs: string[]; expected: Parameter[] }) => {
|
||||
const flaggedInputs = inputs.map(input => `${flag} ${quote([input])}`).join(' ');
|
||||
const rawData = `curl https://example.com ${flaggedInputs}`;
|
||||
expect(convert(rawData)).toMatchObject([{
|
||||
headers: expected,
|
||||
}]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -46,7 +46,12 @@ const importCommand = (parseEntries: ParseEntry[]): ImportRequest => {
|
||||
|
||||
// Start at 1 so we can skip the ^curl part
|
||||
for (let i = 1; i < parseEntries.length; i++) {
|
||||
const parseEntry = parseEntries[i];
|
||||
let parseEntry = parseEntries[i];
|
||||
// trim leading spaces between parsed entries
|
||||
// regex won't match otherwise (e.g. -H 'Content-Type: application/json')
|
||||
if (typeof parseEntry === 'string') {
|
||||
parseEntry = parseEntry.trim();
|
||||
}
|
||||
|
||||
if (typeof parseEntry === 'string' && parseEntry.match(/^-{1,2}[\w-]+/)) {
|
||||
const isSingleDash = parseEntry[0] === '-' && parseEntry[1] !== '-';
|
||||
|
Loading…
Reference in New Issue
Block a user