mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-07-13 08:13:00 +02:00
Fix curl import when using boolean flags
This commit is contained in:
@@ -27,12 +27,13 @@ const SUPPORTED_ARGS = [
|
|||||||
['request', 'X'], // Request method
|
['request', 'X'], // Request method
|
||||||
DATA_FLAGS,
|
DATA_FLAGS,
|
||||||
].flatMap((v) => v);
|
].flatMap((v) => v);
|
||||||
|
const BOOL_FLAGS = ['G', 'get', 'digest'];
|
||||||
|
|
||||||
type Pair = string | boolean;
|
type Pair = string | boolean;
|
||||||
|
|
||||||
type PairsByName = Record<string, Pair[]>;
|
type PairsByName = Record<string, Pair[]>;
|
||||||
|
|
||||||
export function pluginHookImport(ctx: Context, rawData: string) {
|
export function pluginHookImport(_ctx: Context, rawData: string) {
|
||||||
if (!rawData.match(/^\s*curl /)) {
|
if (!rawData.match(/^\s*curl /)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -140,11 +141,12 @@ function importCommand(parseEntries: ParseEntry[], workspaceId: string) {
|
|||||||
|
|
||||||
let value;
|
let value;
|
||||||
const nextEntry = parseEntries[i + 1];
|
const nextEntry = parseEntries[i + 1];
|
||||||
|
const hasValue = !BOOL_FLAGS.includes(name);
|
||||||
if (isSingleDash && name.length > 1) {
|
if (isSingleDash && name.length > 1) {
|
||||||
// Handle squished arguments like -XPOST
|
// Handle squished arguments like -XPOST
|
||||||
value = name.slice(1);
|
value = name.slice(1);
|
||||||
name = name.slice(0, 1);
|
name = name.slice(0, 1);
|
||||||
} else if (typeof nextEntry === 'string' && !nextEntry.startsWith('-')) {
|
} else if (typeof nextEntry === 'string' && hasValue && !nextEntry.startsWith('-')) {
|
||||||
// Next arg is not a flag, so assign it as the value
|
// Next arg is not a flag, so assign it as the value
|
||||||
value = nextEntry;
|
value = nextEntry;
|
||||||
i++; // Skip next one
|
i++; // Skip next one
|
||||||
|
|||||||
@@ -196,6 +196,27 @@ describe('importer-curl', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Imports post data into URL', () => {
|
||||||
|
expect(
|
||||||
|
pluginHookImport(ctx, 'curl -G https://api.stripe.com/v1/payment_links -d limit=3'),
|
||||||
|
).toEqual({
|
||||||
|
resources: {
|
||||||
|
workspaces: [baseWorkspace()],
|
||||||
|
httpRequests: [
|
||||||
|
baseRequest({
|
||||||
|
method: 'GET',
|
||||||
|
url: 'https://api.stripe.com/v1/payment_links',
|
||||||
|
urlParameters: [{
|
||||||
|
enabled: true,
|
||||||
|
name: 'limit',
|
||||||
|
value: '3',
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Imports multi-line JSON', () => {
|
test('Imports multi-line JSON', () => {
|
||||||
expect(
|
expect(
|
||||||
pluginHookImport(
|
pluginHookImport(
|
||||||
|
|||||||
Reference in New Issue
Block a user