Repository navigation
WIP: fix(redirect): ambiguity gate field-count fix (#1769) - #1780
Merged
Merged
Conversation
…pace heuristic (#1769) GNU redir.c:298 redirection_expand returns NULL exactly when the expanded word list has zero or more than one field, and subst.c:12602 glob_expand_word_list makes one list entry per match without word-splitting the matches. A single glob match is therefore one field even when its name contains whitespace, but the gate judged the joined carrier String with a space heuristic and could not tell one space-containing field from two fields: `echo X > only*.txt` with one file `only one.txt` reported ambiguous redirect instead of opening it. expand_redirect_operand_fields now returns the field-count fact alongside the carrier String (true only for the single-match arm), kept in a per-redirect memo beside redirect_target_memo and consulted by both ambiguity gates (redirect_operand_ambiguous and the apply-time direct call). Every other arm returns false, so the existing behavior is untouched: multi-match joins, brace alternatives, no-match literals and failglob patterns still go through the textual gate, and an unquoted $var that word-splits stays ambiguous. The #1673 extglob introducer class is not touched; only the false-positive face changes. Fixes #1769
caomengxuan666
force-pushed
the
fix9/glob-ambig1769
branch
from
October 26, 2026 14:29
84bacba to
66fcf9b
Compare
caomengxuan666
marked this pull request as ready for review
October 26, 2026 17:50
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.
Fixes #1769
Gates landed on rebased head 66fcf9b (base: master 3d97ab4). Rebase conflicts with merged #1764 were resolved by union: the #1673 extglob introducer class is preserved in both gates, and the #1769 single-glob-match exemption is kept alongside it.
Fix: the redirect ambiguity gate judged the joined carrier String with a space heuristic and could not tell one space-containing field from two fields. GNU redir.c:298 returns NULL exactly when the expanded word list has zero or more than one field, and subst.c:12602 glob_expand_word_list makes one list entry per match without word-splitting matches — so one match is one field even when its name contains whitespace.
expand_redirect_operand_fieldsnow returns the field-count fact (true only for the single-match arm) in a per-redirect memo besideredirect_target_memo, consulted by both gates (redirect_operand_ambiguousand the apply-time direct call in redirection.rs). All other arms return false, so multi-match, brace alternatives, no-match literals, failglob and unquoted-$var word-splits keep exactly their current behavior; the #1673 extglob introducer class is untouched.Gates (rebased tree):
ownership_unary_operators_check_existing_file) / 1 ignored — failure set == baseline.One non-attributable exception, left for main-session adjudication (PR stays draft, not self-merged):
cat_redirect_stream_regressions0/2 fails withbash shim: cannot locate niu.exe— its harness resolves the shell viaCARGO_BIN_EXE_bash(the Windows shim), which cannot run on a Linux checkout; the failure occurs before any shell semantics execute, and the same three operations run against the realtarget/debug/rubashbinary keep the full 82,665-byte payload. The underlying niubash#198 behavior is intact; the harness preference is a Linux-dev gap, not a product regression.Regression tests: tests/issue1769_redirect_ambiguity_space_match_regressions.rs (11 tests: plain/extglob/append/input single-with-space, single-no-space, multi-match rc + continuation, zero-match literal, unquoted-var-split stays ambiguous, brace-multi stays ambiguous, quoted single-with-space).