-
Notifications
You must be signed in to change notification settings - Fork 23.5k
fix(editor): Import multipart form data from curl command correctly #14898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,5 +292,45 @@ describe('useImportCurlCommand', () => { | |
expect(parameters.sendBody).toBe(false); | ||
expect(parameters.options.allowUnauthorizedCerts).toBe(true); | ||
}); | ||
|
||
test('Should parse json body data', () => { | ||
const curl = | ||
'curl -X POST https://reqbin.com/echo \ | ||
-H "Content-Type: application/x-www-form-urlencoded" \ | ||
-d "grant_type=authorization_code" \ | ||
-d "code=abc" \ | ||
-d "redirect_uri=https://test.app.n8n.cloud/webhook-test/12345" \ | ||
-d "client_id=app-4343434" \ | ||
-d "client_secret=secret"'; | ||
const parameters = toHttpNodeParameters(curl); | ||
|
||
expect(parameters.url).toBe('https://reqbin.com/echo'); | ||
expect(parameters.method).toBe('POST'); | ||
expect(parameters.sendBody).toBe(true); | ||
expect(parameters.bodyParameters).toEqual({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing verification of the contentType property which should be 'form-urlencoded' |
||
parameters: [ | ||
{ | ||
name: 'grant_type', | ||
value: 'authorization_code', | ||
}, | ||
{ | ||
name: 'code', | ||
value: 'abc', | ||
}, | ||
{ | ||
name: 'redirect_uri', | ||
value: 'https://test.app.n8n.cloud/webhook-test/12345', | ||
}, | ||
{ | ||
name: 'client_id', | ||
value: 'app-4343434', | ||
}, | ||
{ | ||
name: 'client_secret', | ||
value: 'secret', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,14 @@ const extractQueries = (queries: JSONOutput['queries'] = {}): HttpNodeQueries => | |
}; | ||
|
||
const jsonBodyToNodeParameters = (body: JSONOutput['data'] = {}): Parameter[] | [] => { | ||
if (typeof body === 'string') { | ||
const parameters = body.split('&'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing URL-decoding for form-urlencoded data. Form data usually contains encoded characters (like %20 for spaces or + for spaces) that need decoding. |
||
|
||
return parameters.map((parameter) => { | ||
const [key, value] = parameter.split('='); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Splitting by first '=' character can break values containing '=' characters. Form values might include URL parameters or Base64 data containing '=' characters. |
||
return toKeyValueArray([key, value]); | ||
}); | ||
} | ||
return Object.entries(body).map(toKeyValueArray); | ||
}; | ||
|
||
|
@@ -220,7 +228,6 @@ export const flattenObject = <T extends Record<string, unknown>>(obj: T, prefix | |
|
||
export const toHttpNodeParameters = (curlCommand: string): HttpNodeParameters => { | ||
const curlJson = curlToJson(curlCommand); | ||
|
||
const headers = curlJson.headers ?? {}; | ||
|
||
lowerCaseContentTypeKey(headers); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test name 'Should parse json body data' is incorrect as the test is actually parsing form-urlencoded data, not JSON