fix: strip curl --form value modifiers from imported filename#9864
fix: strip curl --form value modifiers from imported filename#9864officialasishkumar wants to merge 2 commits intoKong:developfrom
Conversation
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
|
|
There was a problem hiding this comment.
💡 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".
| const semiIndex = rawValue.indexOf(';'); | ||
| const content = semiIndex === -1 ? rawValue : rawValue.slice(0, semiIndex); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
Handled in b95c2db. The form modifier parser now respects quoted semicolons and unquotes form values/filenames.
Summary
cURL's
--form/-Fflag 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 likecurl -F 'data=@/tmp/a.json;type=application/json'used to stage a file named
/tmp/a.json;type=application/jsonthat cannot be read.Fix
In
extractBody(packages/insomnia/src/main/importers/importers/curl.ts), split each--formvalue at the first;and keep only the content portion as the filename (or literal value). Modifiers like;type=are dropped: Insomnia already derives the multipartContent-Typefrom the file extension viamime-types, which covers the common case this ticket describes.Tests
Seven new cases in
packages/insomnia/src/main/importers/importers/curl.test.ts:--formwith a plainkey=valuetext field.--formwith a simple@filereference.--formwith@file;type=<mime>- modifier dropped, filename preserved.--formwith@file;filename=<name>- modifier dropped, filename preserved.--formwith chained modifiers@file;type=...;filename=...- all dropped.--formwith a text value followed by;type=- modifier dropped, value preserved.-Falias exercising the same modifier-stripping behavior.Test plan
npx vitest run src/main/importers/importers/curl.test.tspasses (49/49).npx vitest run src/main/importers/passes (189/189).npm run lintpasses.Closes #6731