Skip to content

fix(jq): ignore unread invalid stdin under -n - #2660

Merged
chaliy merged 1 commit into
mainfrom
claude/jq-null-input-stdin
Oct 9, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/jq-null-input-stdin

Conversation

@chaliy

@chaliy chaliy commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

With -n, jq no longer reports invalid JSON on stdin that the filter never reads. A stdin parse error is reported only after input or inputs reads past the last valid value, which matches jq 1.7.

Why

jq -n is the usual way to build JSON from --arg values. Scripts often run it while stdin holds something else, such as a pipe or a while read loop's here-doc. bashkit printed the right output, then added jq: invalid JSON ... and exited 5. That breaks set -e scripts that work under real bash. Found during the BashBox re-run (#2657).

Before/After (verified)

printf 'not json' | jq -n '"x"'; echo "rc=$?"
while read -r l; do jq -n --arg v "$l" '$v'; done <<X
one
X
  • Real bash and jq 1.7: "x", then rc=0, then "one".
  • Before: each output was followed by jq: invalid JSON: expected ident ..., and the first command ended with rc=5.
  • After: output is identical to real bash.

The following cases behave the same as jq 1.7:

  • printf '1 x' | jq -n input prints 1 with status 0.
  • printf '1 x' | jq -n '[inputs]' still fails with status 5.

Risk

Low. The change only applies with -n, and only to whether a parse error is reported. Values are still parsed eagerly as before.

Checklist

  • failing tests written first (null_input_ignores_unread_invalid_stdin, null_input_reports_invalid_stdin_once_reached)
  • jq unit tests (348), jq spec tests, clippy -D warnings, fmt
  • knowledge/log.md updated

Generated by Claude Code

@chaliy chaliy self-assigned this Oct 9, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit aaf5529 Commit Preview URL

Branch Preview URL
Oct 09 2026, 04:37 PM

@chaliy
chaliy merged commit 93fdd3f into main Oct 9, 2026
46 checks passed
@chaliy
chaliy deleted the claude/jq-null-input-stdin branch October 9, 2026 16:59
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.

1 participant