Skip to content

fix(jq): fix argument parsing, add test coverage, update docs#221

Merged
chaliy merged 2 commits intomainfrom
claude/fix-jq-argument-parsing-DE4Y3
Feb 19, 2026
Merged

fix(jq): fix argument parsing, add test coverage, update docs#221
chaliy merged 2 commits intomainfrom
claude/fix-jq-argument-parsing-DE4Y3

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 19, 2026

Summary

  • Fix jq argument parsing: combined short flags (-rn, -sc, -snr), --arg name value, --argjson name value, --indent N, and -- separator now work correctly
  • Add comprehensive positive and negative test coverage (10 new unit tests, 8 new spec tests, 2 unskipped spec tests)
  • Update specs (009-implementation-status, 005-builtins) and compatibility docs with full jq flag documentation

Test plan

  • cargo fmt --check passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • cargo test --all-features passes (all 37 jq unit tests, 100/108 spec tests pass, 8 skipped)
  • Negative tests cover: invalid JSON input, invalid filter syntax, invalid --argjson value, empty/whitespace input
  • Positive tests cover: NDJSON, multiple --arg bindings, --argjson with objects, combined flags, exit status for null/false/truthy

… --argjson

The jq builtin's argument parser had several issues:

- Combined short flags (e.g., -rn, -sc) were silently ignored because
  the parser only matched exact single-flag strings like "-r" or "-n"
- --arg name value and --argjson name value were not handled, causing
  the name argument to be misidentified as the jq filter and the actual
  filter to be treated as a file argument ("Could not open file" errors)
- --indent N was not handled, causing N to be misidentified as the filter
- -- (end of options separator) was not supported

Fixes:
- Switch from iterator to index-based arg loop to consume multi-arg flags
- Parse combined short flags by iterating over characters (e.g., -rn -> -r + -n)
- Handle --arg/--argjson by consuming 2 extra args and passing variable
  bindings to jaq Compiler::with_global_vars and Ctx::new
- Handle --indent N, --args, --jsonargs, and -- separator
- Skip unknown long flags gracefully

https://claude.ai/code/session_01JKnPuxK6nH19jUhfc2UVst
…docs

- Unskip jq_try and jq_debug spec tests (both pass with jaq)
- Add 8 new spec tests: empty input, NDJSON, multiple --arg, --argjson
  with objects, combined -snr flags, exit status for false/truthy
- Add 10 new unit tests: invalid JSON, invalid filter, invalid argjson,
  empty/whitespace input, NDJSON, exit status, multiple bindings,
  combined flags
- Update skip reasons to be precise about jaq limitations
- Update 009-implementation-status: 108 tests (100 pass, 8 skip)
- Update 005-builtins: document --arg, --argjson, -V, combined flags
- Update compatibility.md: list all supported jq flags

https://claude.ai/code/session_01JKnPuxK6nH19jUhfc2UVst
@chaliy chaliy merged commit 81e41a5 into main Feb 19, 2026
15 checks passed
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