Repository navigation
WIP: cd-face trio — comsub empty operands, logical pwd rendering, cdable_vars diagnostic name - #2230
Merged
Merged
Conversation
…es empty/splitting operands
split_shell_words_with_quote_info dropped a word whenever its accumulated
text was empty, so a quoted empty string ("" or '') vanished from the word
list. In GNU, quotation produces a word even when it expands to nothing —
the empty word disappears only later, when an UNQUOTED expansion yields no
fields (subst.c expand_word_list_internal / expand_string: a quoted empty
expansion stays as one empty field; cd then rejects the empty operand with
"cd: null directory", builtins/cd.def:333). Track word-started in the
splitter (quote opens, including the $".." locale form, and the $'..'
ANSI-C form, which the splitter already marks quoted) and push a started
word at separators and at end of input.
The $(cd X && pwd) fast path took words.get(1) as its operand, so
$(cd "" && pwd) looked operand-less and silently performed the $HOME
move. It now reads the operand through the quote-aware splitter and
declines (returns None, so the real executor runs the genuine cd/pwd
pair) whenever the word is empty before expansion, empty after expansion,
or an unquoted expansion containing blanks (field splitting is the real
parser's mechanism, not this model's).
Blast radius of the splitter change, audited per consumer: the comsub
word shortcut is gated by a char whitelist that excludes quotes; the
embedded-mutation function-call gate excludes quotes and requires
non-empty words; env -S splitting gains exactly the empty arguments GNU
coreutils env -S preserves; the alias splice and heredoc-delimiter
extraction move toward GNU's re-parse shapes. Pins: 9 tests in
tests/issue2219_comsub_cd_empty_operand_regressions.rs (7 red on master,
2 controls green both ways).
Refs #2219
…ub cd fast path The $(cd X && pwd) fast path returned canonicalize() output — the physical path — for both pwd spellings. GNU's pwd_builtin with no -P prints $PWD, the logical chain cd_builtin maintains (builtins/cd.def: bindpwd stores the logical spelling; the -L default keeps `..` and symlink components unresolved). So $(cd link && pwd) printed the resolved target directory where GNU prints the path through the link, and $(cd //etc && pwd) lost the POSIX double-slash root. The physical probe still gates the fast path (existence / is-dir), but the bare-pwd rendering now goes through the builtin's own chain — logical_destination_display over validated_logical_pwd, exposed from the cd module as logical_destination_display_from — so the fast path cannot drift from the builtin it models; pwd -P keeps the physical rendering. Rendering (rather than declining logical spellings) also avoids re-expanding the operand: declining would run a side-effecting operand twice (once in the fast path's probe expansion, once in the real executor). Known stacking dependency: logical_destination_display itself carries a // seam on master (old="/" + relative operand manufactures //, old="//" + relative collapses); PR #2218 fixes that helper. On this base the fast path and the builtin agree on every probed cell because they share the helper; the cd // session cells verify fully once #2218 is in the base. Pins: 9 tests in tests/issue2220_comsub_pwd_logical_rendering_regressions.rs (5 red on master, 4 controls green both ways; symlink fixtures are unix-only, matching the #2211 cluster's local-dev test target). Refs #2220
…ed value NOTE — the issue prose has the direction swapped; the oracle is unambiguous. GNU (builtins/cd.def, cd_builtin error tail) prints sh_whence / printable_filename(dirname) where dirname is the OPERAND as given: the CDPATH/cdable_vars attempts bind a separate temp and never reassign dirname; only the errno comes from the last attempt. Verified against bash 5.3.20: cdable_vars=1 CDPATH= DEST=dest with dest a shell variable holding /no/such/dir-xyz gives "cd: dest: No such file or directory" — the operand's name with the value's errno. The two cases where GNU names the value are different mechanisms: the cdable SUCCESS message prints the substituted path (LCD_DOVARS), and `cd -` reassigns dirname = $OLDPWD before the attempts. rubash named the substituted value because resolve_cdable_vars had already replaced target.display with the value's Target before the canonicalize probe failed. Keep the operand's display name (dirname_display) before resolve_cdpath / resolve_cdable_vars run and use it in the probe-failure diagnostic; the errno still comes from probing the attempted value. Pins: 5 tests in tests/issue2221_cdable_vars_diag_regressions.rs (2 red on master; controls pin the success-message and cd - exceptions plus a plain missing operand). Refs #2221
Master carries PR #2218 (rubash#2211: comsub cd session-cwd anchoring, operand decline gates, logical_destination_display // seam fix in paths.rs), PR #2224 (census) and PR #2226 (walker) since this branch forked at 01836d3. One conflict, in command_substitution_cd_pwd_output_impl (src/executor/command_substitution.rs), resolved as the union of both sides per the cluster REPORT overlap map: - operand read stays quote-aware (split_shell_words_with_quote_info, #2219): the raw-empty decline is decided pre-expansion; - #2211's post-expansion declines kept (leading '-', CDPATH search, expanded-empty) and operand_form is set only after every decline has passed; - #2219's unquoted-blank (field-splitting) decline kept; - downstream untouched: session-cwd anchoring (#2211), the cdable decline keyed on operand_form, and the #2220 logical rendering tail over paths.rs's seam-fixed logical_destination_display. Re-verified on the merged tree (Linux): issue2219 9/9, issue2220 9/9 (incl. the //etc pin), issue2221 5/5, issue1415 adjacency 1/1, issue2211 14/14 (the session-// + relative-operand seam cells are pinned there), --lib 983 pass / 0 fail.
caomengxuan666
marked this pull request as ready for review
October 30, 2026 14:12
This was referenced Oct 30, 2026
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.
WIP: cd-face trio — empty comsub operands (#2219), logical pwd rendering (#2220), cdable_vars diagnostic name (#2221)
Cluster branch for the three cd-face divergences filed from the #2211 probes. One commit per issue; Refs-only.
split_shell_words_with_quote_infodropped quoted empty words, so$(cd "" && pwd)looked operand-less and silently did the $HOME move. Splitter now tracks word-started; the comsub cd fast path declines empty/splitting operands to the real executor. (commit 1)$(cd X && pwd)fast path rendered the physical path for barepwd; it now renders through the builtin's own logical chain (logical_destination_display_from),pwd -Pkeeps the physical rendering. (commit 2)dirname) and takes only the errno from the last attempt. Commit 3 keeps the operand's display name (the issue prose had the direction swapped vs the oracle; evidence in the cluster report).Overlap note: PR #2218 (the #2211 fix) edits the same
command_substitution_cd_pwd_output_impl. #2218 restructures the operand gating (session-cwd anchoring + its own decline gates) and fixeslogical_destination_display's//seam insrc/builtins/cd/paths.rs; this branch deliberately does not touch paths.rs and builds on the helper. Whichever lands second takes a master merge-in; the full gate adjudicates. On this base the fast path agrees with the builtin on every probed cell (they share the helper); thecd //+ relative-operand cells additionally depend on #2218's helper fix.Verification so far (local, Linux): pins 23/23 green on the fixed tree; baseline (src stashed) 14 red / 9 green across the three targets;
--lib983 passed / 0 failed; issue1415 adjacency green; probe batteries byte-identical to the GNU bash 5.3.20 oracle except the #2218-owned//-seam cells documented in the pins.Refs #2219
Refs #2220
Refs #2221