Skip to content

Use --form-string for form fields to prevent unintended file inclusion - #104

Open
Huge wants to merge 2 commits into
rs:masterfrom
Huge:fix/form-string-values
Open

Huge wants to merge 2 commits into
rs:masterfrom
Huge:fix/form-string-values

Conversation

@Huge

@Huge Huge commented Oct 11, 2026

Copy link
Copy Markdown

Summary

In HTTPie syntax, field=value request items specify text form fields whose values are passed as literal strings. When forwarding to curl in form mode (--form), curlie previously translated these items into -F name=value.

Under curl's -F syntax, values beginning with @ or < have special meaning and are interpreted as local file paths to be read and uploaded, rather than literal strings:

  • If the referenced file exists on disk, its contents are read and uploaded in the multipart request body.
  • If the file does not exist, curl fails with exit code 26 (curl: (26) Failed to open/read local data from file/application).

Curl provides --form-string name=value specifically to pass field values literally without interpreting @ or < as file references.

Changes

  • In args/httpie.go, translate fieldArg in PostModeFORM to --form-string name=value instead of -F name=value.
  • In main.go, update the isForm check to recognize opts.Has("form-string") so that multipart form requests are properly handled without appending redundant JSON Content-Type headers.
  • In args/parse_test.go, add unit test TestParseForm verifying that form fields with @ and < values are mapped to --form-string.

Test Plan

  • Run go test -v ./... (passes with new test case).
  • Run go vet ./... (clean).
  • Verified with curl that --form-string properly preserves @ and < values in form payloads without attempting to access local files.

In HTTPie syntax, field=value form items are text fields whose values
are sent as literal strings. When forwarding to curl in form mode, curlie
passed -F name=value.

Under curl's -F syntax, values beginning with @ or < are interpreted
as local file paths to be read and uploaded, rather than literal strings.
If the referenced file exists, its contents are uploaded; if not, curl
fails with an error (exit code 26).

Curl provides --form-string specifically to pass field values literally
without interpreting @ or < as file references. Using --form-string
ensures consistent behavior with HTTPie and avoids unintended file reads.

Reported-by: BS.ehlas.cz
@Huge
Huge marked this pull request as draft October 11, 2026 11:03
@Huge
Huge marked this pull request as ready for review October 11, 2026 11:04
@rs

rs commented Oct 14, 2026

Copy link
Copy Markdown
Owner

This change would remove a useful existing capability: using field=@file or field=<file to upload files or their contents through curl’s -F syntax.

I’m fine with aligning the behavior with HTTPie and treating field=value as a literal string, but I’d only accept this PR if it also introduces HTTPie’s field@file syntax for file uploads, so we don’t lose that functionality.

Since form fields are now passed with --form-string, curl's
field=@file / field=<file shortcuts no longer read local files.
Add HTTPie's dedicated file upload item instead: with --form,
field@path becomes -F field=@path, so the upload is explicit and a
literal value starting with @ or < is never taken as a file name.
An optional ;type=mime suffix is passed through to curl, matching
HTTPie's field@path;type=mime.

The @ separator follows HTTPie's first-found rule, so items such as
email=me@example.com, From:me@example.com and q==a@b keep their
current meaning.

Like HTTPie, file fields are only valid with --form; in JSON mode
curlie now exits with "invalid file fields (perhaps you meant
--form?)" instead of passing the item to curl as an extra URL.
Parse returns an error to report this.

Reported-by: BS.ehlas.cz
@Huge

Huge commented Oct 15, 2026

Copy link
Copy Markdown
Author

Added support for HTTPie's field@path file upload syntax in --form mode (forwarded to curl as -F field=@path, including passthrough for ;type=mime), while keeping field=value form items as literal strings via --form-string.

When file upload fields are passed without --form (in default JSON mode), curlie now reports an error matching HTTPie's behavior (invalid file fields (perhaps you meant --form?)).

Added test coverage for file fields, MIME types, literal @ values, and added a README example.

This branch has not been deployed

No deployments
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.

2 participants