Skip to content

Fix JSON request corruption with piped stdin - #103

Open
jovial-liu wants to merge 2 commits into
rs:masterfrom
jovial-liu:fix/explicit-json-stdin
Open

jovial-liu wants to merge 2 commits into
rs:masterfrom
jovial-liu:fix/explicit-json-stdin

Conversation

@jovial-liu

@jovial-liu jovial-liu commented Oct 8, 2026 •

Copy link
Copy Markdown

Piped stdin currently appends -d@- even when explicit --json already supplies a request body. With --json @-, that adds an extra &; with inline/file JSON it appends unintended input.

Detect explicit --json and --expand-json in 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.

@rs
rs requested a balanced review from Copilot October 8, 2026 21:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 --json and --expand-json options.
  • 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 thread args/parse.go
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

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.

--json @- adds an extra & character at the end

2 participants