Repository navigation
fix(expansion/pipeline/invocation): four fast-path fidelity bugs found via differential testing vs GNU bash - #101
Merged
caomengxuan666 merged 4 commits intoSep 14, 2026
Conversation
Harnesses spawn '<shell> -lc <script>'; GNU bash parses the combined login+command form. Expand combined short flags for 'l' as well, but only for single-dash words: the previous 'l' whitelist addition also exploded '--rcfile' (every char whitelisted) into '-r -c -f ...'.
…-word re-expansion
Command substitution took word-based fast paths whose splitter drops
quote delimiters, so bodies with semantically visible quotes arrived at
the emulated command corrupted: $(echo '{"a":1}') reached echo as the
bare word {a:1}, and a de-escaped \" inside double quotes degraded to a
literal backslash (lexer emitted a bare quote that downstream scanners
toggled state on and swallowed: echo "a\"b" printed ab, bash prints
a"). Route such bodies through the real parser/executor; top-level
quote delimiters merely group words and keep the fast paths the heredoc
backtick-literal and IFS read regressions rely on.
Also:
- argument words shaped name='a"b' lost the quote across the
embedded-parameter re-scan (parameter_core) — hoist data quotes with
the same sentinel the assignment-storage path uses
(hoist_data_double_quotes, now pub(in crate::executor));
- the unclosed-compound precheck misread 'done; echo x' as an unclosed
loop because split_shell_words keeps ';' attached to the terminator
word — trim trailing separators before comparing;
- regression test command_substitution_preserves_nested_quote_literals
pins six quote shapes against GNU bash output.
…odeled flags The inline emulations of sort/head/grep/tail/uniq inside cmdsub pipelines silently ignored or mis-consumed flags they do not model: sort -r ran as sort -u, head -c emitted whole lines, a grep flag (e.g. -c) became the pattern, any uniq flag was dropped. Bail out to the real parser (which runs the actual tool) whenever the operands are not exactly the modeled shape.
Per-process temp roots let concurrent tilde_* tests share (and remove_dir_all) each other's passwd fixture, making tilde_user_resolves_passwd_home flake; give every call its own root.
Member
|
Thank you @SuperYogurt for this contribution — merged. 🙏 The four fixes here are exactly the class of bug that's hardest to catch by hand: fast paths that produce plausible-looking but wrong output instead of failing loudly. Byte-exact differential testing against GNU bash is the right way to surface them, and the guard against exploding long options ( The quote-literal preservation work (commit 2) also fixed four pre-existing test failures as a bonus — much appreciated. We'll credit this in the next release notes. If you run more differential batteries, the "known-deferred" |
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.
Why
rubash is used daily as a Windows replacement shell under an agent harness (thousands of
rubash -c '<script>'invocations against GNU bash reference behaviour). A 36-family byte-exact differential battery against GNU bash surfaced four fast-path fidelity bugs: places where an emulation shortcut produced silently wrong output instead of failing loudly. Each reproduction below is byte-checked against GNU bash after the fix.Commits
1. fix(invocation): accept combined
-lc/-ilcwithout exploding long optionsbash -lc 'echo hi'is rejected; harnesses andtmux default-shellspawn exactly this form. Also adds a guard the previous combined-flag expansion lacked: long options must never be exploded (--rcfilewas split into-r -c -f ...onceljoined the whitelist, because every character ofrcfileis a whitelisted flag char).2. fix(expansion): preserve quote literals through cmdsub and assignment-word re-expansion
Command substitution's word-based fast paths use a splitter that drops quote delimiters, but GNU
subst.calways parses the body — so bodies whose quotes must survive into the output arrive corrupted:The routing predicate (
command_substitution_quotes_are_semantic) deliberately fires only for quotes whose literal value is semantically visible (nested quotes,\"/\inside"): top-level delimiters merely group words, stripping them matches bash, and bodies routed through the full executor regress the heredoc old-style backtick literal and the IFSreadsplitting cases (verified: those two probes fail with an unconditional detour).Pins six quote shapes in
command_substitution_preserves_nested_quote_literals.3. fix(pipeline): fall back to real commands when inline filters see unmodeled flags
Inline emulations of
sort/head/grep/tail/uniqinside$(... | cmd)silently swallowed or mis-consumed flags they do not model — the worst kind of failure because output looks fine:Each arm now bails out to the real parser whenever operands are not exactly the modeled shape. Pins GNU bash's byte-exact output in
cmdsub_inline_filters_run_real_commands_for_unmodeled_flags.(The companion bug — the pipeline first stage spawning through
CreateProcessand resolving to System32sort.exe— was fixed here in an earlier revision of this branch, but is superseded upstream byc59c5da4(run external pipelines through the real executor, issue #76), which covers it from the better side. That commit is intentionally not included.)4. test(tilde): unique fixture roots under thread-parallel cargo test
tilde_user_resolves_passwd_homeflakes undercargo test: fixtures are named per-process while tests run as threads of one process, so concurrent runs share (andremove_dir_all) each other's root. Per-call unique roots.Test plan
cargo test --lib: 384 passed, 0 failed (Windows host + Linux CI expected identical)cargo test --test cli_tests: full-suite differential againstorigin/masterrun on the same machine with exact failure-set comparison (not just counts): 0 new failures, and 69 failing tests on master become 65 on the branch — the quote-fidelity changes in commit 2 also make four preexisting failures pass (bashdb_compat::eval_can_reparse_quoted_associative_array_append,bashdb_compat::line_continuation_after_apostrophe_inside_double_quotes_keeps_one_command,bashdb_compat::quoted_assignment_like_argument_is_not_array_assignment_parse_error,compat_issue_regressions::quoted_process_substitution_stays_literal), plus the 2 new regression tests.Known-deferred (not in scope, found by the same battery)
[directly after the opening quote of a double-quoted word around a$(...)leaks the0x11glob carrier into output — systemic marker-protocol work, test shapes in commit 3 avoid it on purpose.