Skip to content

fix: strip curl --form value modifiers from imported filename#9864

Open
officialasishkumar wants to merge 2 commits intoKong:developfrom
officialasishkumar:fix/curl-form-file-type-modifier
Open

fix: strip curl --form value modifiers from imported filename#9864
officialasishkumar wants to merge 2 commits intoKong:developfrom
officialasishkumar:fix/curl-form-file-type-modifier

Conversation

@officialasishkumar
Copy link
Copy Markdown

Summary

cURL's --form/-F flag accepts trailing modifiers after a semicolon such as ;type=<mime>, ;filename=<name>, ;headers=@<file> and ;encoder=<enc>. Insomnia was treating the whole suffix as part of the filename. Importing a command like

curl -F 'data=@/tmp/a.json;type=application/json'

used to stage a file named /tmp/a.json;type=application/json that cannot be read.

Fix

In extractBody (packages/insomnia/src/main/importers/importers/curl.ts), split each --form value at the first ; and keep only the content portion as the filename (or literal value). Modifiers like ;type= are dropped: Insomnia already derives the multipart Content-Type from the file extension via mime-types, which covers the common case this ticket describes.

Tests

Seven new cases in packages/insomnia/src/main/importers/importers/curl.test.ts:

  • --form with a plain key=value text field.
  • --form with a simple @file reference.
  • --form with @file;type=<mime> - modifier dropped, filename preserved.
  • --form with @file;filename=<name> - modifier dropped, filename preserved.
  • --form with chained modifiers @file;type=...;filename=... - all dropped.
  • --form with a text value followed by ;type= - modifier dropped, value preserved.
  • The -F alias exercising the same modifier-stripping behavior.

Test plan

  • npx vitest run src/main/importers/importers/curl.test.ts passes (49/49).
  • npx vitest run src/main/importers/ passes (189/189).
  • npm run lint passes.

Closes #6731

cURL's --form/-F flag accepts trailing modifiers after a semicolon such
as `;type=<mime>`, `;filename=<name>`, `;headers=@<file>` and
`;encoder=<enc>`. Insomnia was treating the whole suffix as part of the
filename, so importing a command like

    curl -F 'data=@/tmp/a.json;type=application/json'

would stage a file named `/tmp/a.json;type=application/json` that
cannot be read.

Split the value at the first `;` and keep only the content portion as
the filename (or literal value). Modifiers like `;type=` are dropped
because Insomnia derives the multipart Content-Type from the file
extension via `mime-types`, which covers the common case this ticket
describes.

Closes Kong#6731
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86b953b64b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +181 to +182
const semiIndex = rawValue.indexOf(';');
const content = semiIndex === -1 ? rawValue : rawValue.slice(0, semiIndex);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Respect quoted semicolons in --form values

Splitting rawValue at the first ; breaks valid curl -F/--form syntax where semicolons are part of quoted data or filenames (for example, -F 'colors="red; green; blue";type=text/x-myapp' and quoted filenames containing ; shown in curl --manual). In those cases this now truncates imported content to the substring before the first semicolon, producing corrupted multipart field values or file paths instead of preserving the quoted literal.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Handled in b95c2db. The form modifier parser now respects quoted semicolons and unquotes form values/filenames.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import from curl does not work properly if a form file field has type def

2 participants