Skip to content

fix(rewrite): read every cat flag, not just the first - #4593

Open
aeppling wants to merge 1 commit into
developfrom
fix/cat-flag-rewrite
Open

aeppling wants to merge 1 commit into
developfrom
fix/cat-flag-rewrite

Conversation

@aeppling

Copy link
Copy Markdown
Contributor

The bug

cat -n -s file was rewritten to rtk read -n -s file. rtk read has no -s, so clap rejected it and the fallback executed a PATH binary named read: a shell builtin stub on macOS, nothing at all on Linux. The command the user typed never ran.

raw:  cat -n -s file   -> exit 0
rtk:  cat -n -s file   -> exit 127   (/usr/bin/read: read: -s: invalid number)

Cause

The guard above the rewrite already said only -n maps to rtk read, but it tested the first argument only:

if args.starts_with('-') && !args.starts_with("-n ") && !args.starts_with("-n\t") {
    return None;
}

Once -n came first, every later flag was waved through. cat -s and cat -b were correctly skipped; cat -n -s and cat -n -b were not.

Fix

Classify every argument through arg_tokenizer and rewrite only when -n is the sole flag and a file is named, which is what the comment claimed all along. Per coding rule 6, a string scan for starts_with('-') is how this slipped in.

read also joins RTK_META_COMMANDS, so a parse failure reports the flag error instead of reaching for a read on PATH. Same reasoning the list already records for err, summary and /bin/test; read was simply missed. It leaves the test's PASSTHROUGH list, which means "wraps a real tool".

Verification

case raw through rtk
cat -n -s f 0 0 runs as typed
cat -n -b f 0 0 runs as typed
cat -n f 0 0 still rewritten to rtk read -n f
rtk read --bogus exit 2 clap's error, was 127

cargo fmt, cargo clippy --all-targets clean, 4467 tests pass.

One pre-existing failure on my machine, a_wrapped_tools_own_help_survives_rtk, is unrelated: npm --help exits 134 (SIGABRT) here, and clean develop fails that test identically with the same numbers.

Provenance

Found by the transparency lab run on 0.49.0: 6 cases, all cat -n -s or cat -n -b, reported as "filter broke a working command" (family C).

🤖 Generated with Claude Code

`cat -n -s file` was rewritten to `rtk read -n -s file`. rtk read has no
`-s`, so clap rejected it and the fallback executed a PATH binary named
`read`: a shell builtin stub on macOS, nothing at all on Linux. The
command the user typed never ran, and the exit code went from 0 to 127.

The guard above the rewrite already said only `-n` maps to rtk read, but
it tested `args.starts_with("-n ")`, so once `-n` came first every later
flag was waved through. It now classifies every argument through
arg_tokenizer and rewrites only when `-n` is the sole flag and a file is
named, which is what the comment claimed all along.

`read` also joins RTK_META_COMMANDS, so a parse failure there reports the
flag error instead of reaching for a `read` on PATH. That is the same
reasoning the list already records for `err`, `summary` and `/bin/test`;
`read` was simply missed. It leaves the test's PASSTHROUGH list, which
means "wraps a real tool".

Found by the transparency lab: 6 cases, all `cat -n -s` or `cat -n -b`,
reported as "filter broke a working command".

Co-Authored-By: Claude Opus 5 <[email protected]>
@CLAassistant

CLAassistant commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working cli area:rewrite labels Oct 16, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes a bug where cat -n -s/cat -n -b (and similar multi-flag combinations) were incorrectly rewritten to rtk read, which lacks those flags and silently failed via PATH fallback. The fix tokenizes all arguments to confirm -n is the only flag before rewriting, and adds read to RTK_META_COMMANDS so parse failures surface clap errors instead of falling through to a PATH binary.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! Before we can review and merge this, the CLA needs to be signed. The CLAassistant bot left the link above, it only takes a minute. Once it's signed we'll pick the review up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:rewrite bug Something isn't working cli

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants