Repository navigation
Fix JSON request corruption with piped stdin - #103
Open
jovial-liu wants to merge 2 commits into
Open
jovial-liu wants to merge 2 commits into
jovial-liu wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
JSON detection incorrectly spans curl --next transfer boundaries, potentially dropping piped data.
1 open finding
What changed in this PR
Prevents piped stdin from corrupting explicit JSON request bodies.
Changes:
- Detects explicit
--jsonand--expand-jsonoptions. - Adds CLI-level HTTP regression tests for JSON input variants.
| File | Description |
|---|---|
main.go |
Suppresses automatic stdin data for explicit JSON bodies. |
args/parse.go |
Adds JSON-option detection. |
main_test.go |
Adds end-to-end request-body tests. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+31
to
+48
| func (opts Opts) HasJSON() bool { | ||
| for i := 0; i < len(opts); i++ { | ||
| opt := opts[i] | ||
| if opt == "--json" || strings.HasPrefix(opt, "--json=") || | ||
| opt == "--expand-json" || strings.HasPrefix(opt, "--expand-json=") { | ||
| return true | ||
| } | ||
| // A value such as an output filename may itself look like --json. | ||
| if strings.HasPrefix(opt, "--") { | ||
| if longHasValue(opt[2:]) { | ||
| i++ | ||
| } | ||
| } else if len(opt) == 2 && opt[0] == '-' && strings.IndexByte(curlShortValues, opt[1]) != -1 { | ||
| i++ | ||
| } | ||
| } | ||
| return false | ||
| } |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Piped stdin currently appends
-d@-even when explicit--jsonalready supplies a request body. With--json @-, that adds an extra&; with inline/file JSON it appends unintended input.Detect explicit
--jsonand--expand-jsonin the parsed options and suppress automatic stdin data for that transfer. Automatic stdin is appended to the final transfer, so JSON state resets at--next/-:. Earlier inline JSON followed by a plain final request retains the final stdin body. Option values that resemble JSON flags or transfer boundaries remain values, including literal bodies, output filenames, headers and attached/compound short options.Fixes #102.
Local macOS/Go 1.27.2/curl 8.7.1 validation: complete tests, race tests, vet, module verification, native build and 17 supported configured cross-compilation targets passed. CLI regressions exercise 31 real HTTP cases and 8 equals-form forwarding cases. The additional transfer-boundary regressions fail 11 of 23 cases on the prior PR head and pass all 23 with this revision. An independent 23-case HTTP matrix improves from original 11 / prior PR 15 to all 23 passing; all 8 forwarding controls pass, preserving every originally passing case in that matrix.
Native curl 8.7.1 rejects long-option equals syntax, so those controls verify forwarding. Explicit curl config-file JSON and existing positional-URL transfer grouping remain outside this repair. Local cross-compilation does not establish execution on other operating systems or a local GoReleaser run. The previous head's successful CI does not establish CI success for this updated commit.
AI-assisted — Tool: OpenAI Codex; model: openai/unavailable; version: unavailable.