Skip to content

WIP: fix(redirect): ambiguity gate field-count fix (#1769) - #1780

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix9/glob-ambig1769
Oct 26, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix9/glob-ambig1769

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

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_fields now returns the field-count fact (true only for the single-match arm) in a per-redirect memo beside redirect_target_memo, consulted by both gates (redirect_operand_ambiguous and 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):

  • issue1769 file: 11/11 passed.
  • Neighbors: issue1029 group 9/9, issue1469 1/1, issue1321_1330 8/8, issue1392 2/2, issue1673 3/3 (in-tree on rebased master; both fixes compose).
  • Lib suite (--skip login_posix_env): 771 passed / 1 failed (only the allowed ownership_unary_operators_check_existing_file) / 1 ignored — failure set == baseline.
  • Diffcorpus: 306 cases, 305 PASS, failure set = {ms10}.
  • Probes on the fixed binary: all 10 shapes match GNU 5.3.20.
  • cargo check green; per-file rustfmt clean on changed lines (pre-existing whole-tree drift untouched); CR count 0.

One non-attributable exception, left for main-session adjudication (PR stays draft, not self-merged): cat_redirect_stream_regressions 0/2 fails with bash shim: cannot locate niu.exe — its harness resolves the shell via CARGO_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 real target/debug/rubash binary 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).

…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
caomengxuan666 marked this pull request as ready for review October 26, 2026 17:50
@caomengxuan666
caomengxuan666 merged commit db5ff08 into master Oct 26, 2026
8 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix9/glob-ambig1769 branch October 30, 2026 01:42
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.

Redirect ambiguity gate false-positives on a single match whose filename contains a space

1 participant