Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mutdmour
Copy link
Contributor

@mutdmour mutdmour commented Apr 25, 2025

Summary

curlconverter returns data as string which is not handled at the moment.
before
Screenshot 2025-04-25 at 14 26 29
after
Screenshot 2025-04-25 at 14 25 46

Related Linear tickets, Github issues, and Community forum posts

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@mutdmour mutdmour requested review from a team and elsmr April 25, 2025 12:29
@n8n-assistant n8n-assistant bot added the n8n team Authored by the n8n team label Apr 25, 2025
Copy link

@mrge-io mrge-io bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mrge found 4 issues across 2 files. View them in mrge.io

@@ -292,5 +292,45 @@ describe('useImportCurlCommand', () => {
expect(parameters.sendBody).toBe(false);
expect(parameters.options.allowUnauthorizedCerts).toBe(true);
});

test('Should parse json body data', () => {
Copy link

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

expect(parameters.url).toBe('https://reqbin.com/echo');
expect(parameters.method).toBe('POST');
expect(parameters.sendBody).toBe(true);
expect(parameters.bodyParameters).toEqual({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing verification of the contentType property which should be 'form-urlencoded'

@@ -149,6 +149,14 @@ const extractQueries = (queries: JSONOutput['queries'] = {}): HttpNodeQueries =>
};

const jsonBodyToNodeParameters = (body: JSONOutput['data'] = {}): Parameter[] | [] => {
if (typeof body === 'string') {
const parameters = body.split('&');
Copy link

Choose a reason for hiding this comment

The 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.

const parameters = body.split('&');

return parameters.map((parameter) => {
const [key, value] = parameter.split('=');
Copy link

Choose a reason for hiding this comment

The 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.

Copy link

codecov bot commented Apr 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant