Repository navigation
fix(cd): tilde-expand CDPATH entries before the search (Refs #3394) - #3479
Merged
Merged
Conversation
Root cause: resolve_cdpath joined each CDPATH unit verbatim, so a `~/...` or bare `~` entry was treated as a relative path: the target was missed when it existed only under the tilde entry, and the cwd copy won when the target existed in both places. GNU anchor: builtins/cd.def:360 `sh_makepath (path, dirname, MP_DOTILDE)`; lib/sh/makepath.c:98 expands a `~`-led element with bash_tilde_expand. The fix expands each `~`-led unit with expand_tilde_segment (the bash_tilde_expand port) before the join, feeding both the filesystem probe and the display spelling, so the announcement prints the found expanded path (cd.def:375-377). Regression nails: tests/issue3394_cdpath_tilde_regressions.rs (8 tests: seed tilde hit, bare `~`, second entry, trailing slash, CDPATH-beats-cwd, -P via symlink, controls, miss/cwd-fallback + unresolvable `~user` verbatim). 本 PR 删除了什么: 无删除;仅新增展开调用与回归钉。 UNVERIFIED-BY-CAPTAIN
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项):
F 点:无。 续作记录:无。 未跑/VOID 的腿:Windows 钉自跑预期 VOID(cfg(unix)),WSL Linux 双侧已覆盖;其余全跑。 |
caomengxuan666
marked this pull request as ready for review
November 15, 2026 02:11
This was referenced Nov 15, 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.
Refs #3394.
根因
resolve_cdpath(src/builtins/cd.rs)把每个 CDPATH 条目按字面拼合:~/...或独条目~被当作相对路径处理——目标仅存于波形条目下时漏检(rc=1 No such file or directory);目标两处皆有时取 cwd 副本。GNU 锚点
sh_makepath (path, dirname, MP_DOTILDE)~开头的条目经bash_tilde_expand展开后再拼合-P下仅 $PWD 取物理目录修法:拼合前对
~开头的条目调expand_tilde_segment(bash_tilde_expand 的既有移植)展开,展开后的 base 同时喂给文件系统探针与 display 拼写。同一调用覆盖~/~/、~+/~-/~N与~user;不可解前缀保持原样。pushd经resolve_search_operand共享同一 funnel,一并受益;$(cd X && pwd)快路的准入判定(command_substitution.rscdpath_search_could_apply)仅为布尔门,不做拼合,无需改动。回归钉
tests/issue3394_cdpath_tilde_regressions.rs(8 个测试,stem
issue3394_cdpath_tilde_regressions):种子波形命中、独~、非首条目、尾斜杠、CDPATH 胜 cwd 副本、~/...+-P经符号链接、两对照(绝对 $HOME 条目、cd 参数自身波形)、缺失回落 cwd + 不可解~user保持原样。期望以 GNU bash 5.3.20 实测为准(种子 seed_r102a.sh 10/10;尾斜杠/两处并存/-P播报三探针已跑,见 REPORT)。本 PR 删除了什么
无删除;仅新增展开调用与回归钉。
验证状态
UNVERIFIED-BY-CAPTAIN。本地写墙间歇发作、Simular box 盘满、老服务器 ssh 未恢复、X299 车道直连未通:本机未编译、未跑钉;fail-first 以 hunt 种子在修前 master 的 4/10(issue 记载)为准,钉与修法同形。
cargo fmt --check(全树)、scripts/check-utf8-boundary-hygiene.sh、scripts/check-marker-literals.py三项已过;RUSTFLAGS="-D warnings" cargo check、新钉 stem、全量 lib 与 base 对齐腿留队长复核轮(X299)。护栏
定点仅 src/builtins/cd.rs + 新钉文件;未碰 src/lexer/continuation.rs、docs/api-ledger.md、executor/path.rs(在飞 PR #3443 面);未引入 trust/签名/加载期校验机制。