Skip to content

fix(canon): realpath -m relative .. ascends from cwd again - #1918

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/canon-1908-realpath-m-dotdot
Nov 28, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/canon-1908-realpath-m-dotdot

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

UNVERIFIED-BY-CAPTAIN — code-only lane delivery; captain runtime review pending.

Refs #1908

根因

回归窗 1.2.1 → 1.2.3(rust2 canon 移植波)。rust2/crates/winux-cmds/src/canon.rs::normalize_lex_native 对相对操作数以空 component stack 起步词法行走:.. 只能弹出操作数自身的分量,永远弹不到 cwd 的分量。于是 cwd=C:\Windows\System32 时:

  • realpath -m .. → C:\Windows\System32(GNU:C:\Windows)
  • realpath -m ../.. → C:\Windows\System32(GNU:C:\)
  • realpath -m ../x → C:\Windows\System32\x(GNU:C:\Windows\x)

readlink -m 同走此函数,同病。分拣卷宗(云端 GNU coreutils 9.4 oracle + 1.2.1 装机正确面 + master 源码同形)三证一致。影响面含「realpath -m 做路径守卫被绕过」(报告人指出,属实)。

改法

normalize_lex_native 内新增 split_anchor:把 cwd 拆成锚(盘符根 X:\ / UNC 共享 \\srv\share\ / 裸根——.. 永不弹出)+ 锚下分量。相对形与 POSIX-rooted 形(无 fold 认领、按 C++ resolver 口径自 cwd 起步)的行走以 cwd 分量为初始 stack,.. 逐级弹出 cwd 分量、到锚钳制。绝对盘符形不变(锚即盘符根、初始 stack 为空)。-e/默认形的存在性路径未触碰。

本 PR 删除了什么

无删除。词法行走仍是 normalize_lex_native 单一走法,只是其 root/rest 计算被替换为 anchor/seed 计算;未加 shim/桥/第二路径。

钉与计数(devin-windows,gnu 工具链,--test-threads=4)

新增 canon::lex_walk_tests 3 钉(先行于修复,fail-first 双向已证):

  • m_relative_dotdot_ascends_from_cwd:-m ..、../..、sub/../..、../x、POSIX-rooted /../x、/sub/../..,及 ./空段/sub/.. 守卫形。改前红(-m .. 得 cwd 本身),改后绿。
  • m_absolute_dotdot_never_crosses_drive_root:绝对形 .. 不越盘符根(守卫钉,改前改后均绿)。
  • m_dotdot_clamps_when_cwd_is_the_drive_root:cwd 在盘符根时 .. 钳制于根(守卫钉)。

计数对账:master lib 共 1096 测;本 PR 后 1099 测(+3 新钉),实测 1098 passed / 1 failed,唯一红 df::tests::type_filters 在未改树上同签名复现(devin-windows 文件系统类型枚举环境面,与本改动无关)。canon 子集 5/5 绿(3 新钉 + 既有 2 钉)。

注:devin-windows 无 VS,msvc 工具链无法链接;本次以 gnu 工具链构建测试(wtsapi32/netapi32 import lib 缺失以本地生成的导入库补齐,仅测试环境手段,未入库)。队长复核可在 X299 msvc 面补跑。

净行:canon.rs +133 / −7(其中新钉约 +110 行)。

@caomengxuan666
caomengxuan666 merged commit 24c6eb6 into main Nov 28, 2026
32 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/canon-1908-realpath-m-dotdot branch November 28, 2026 01:45
caomengxuan666 added a commit that referenced this pull request Nov 30, 2026
* rust2(port+wire): cat -> rust2 library + bridge (#1488)

* fix(cat): route /dev/stdin family operands to stdin

* fix(cat): honor WINUX_SHELL_GLOB=done, trailing-slash dir, and dir-on-stdin (#1803)

* fix(ls): keep printable Unicode literal without POSIX locale (#1883)

Windows filenames cross the narrow boundary as UTF-8 regardless of the
legacy system locale, while interactive ls defaults to shell-escape
quoting. Treating an unset POSIX locale as the C locale made ordinary
CJK names render as octal byte splices for typical Windows users.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(ls): merge adjacent $'...' segments in shell-escape quoting (Fixes #1890)

* fix(ptx): align fallback context truncation to UTF-8 char boundaries

* fix(csplit): preserve trailing literals and UTF-8 in suffix format

* fix(fold): parse numeric width from current index in clustered short options

* fix(od): mask high-order bit in named character output (-a / -t a)

* fix(ptx): slice context and fallback truncations on raw bytes like GNU

* docs: adopt all-contributors, add dingyi580, ShiomiHC, qwased

* fix(canon): realpath -m relative .. ascends from cwd again (Refs #1908) (#1918)

* fix(winux-regex): restore ranges after the first in character classes (#1919)

parse_char_class's is_range required prev_takes_range, so every range
after the first in a bracket expression (or after a POSIX class /
collating element) degraded to literal members: [A-Za-z] lost a-z,
[A-Za-z_]+ silently mis-matched, [[:digit:]a-f] lost a-f. Regression
introduced in 1.2.2 (1.2.1 matches GNU grep 3.12 / sed 4.9).

Drop the prev_takes_range requirement from is_range (one line). The
flag's legitimate use — the Invalid-range-end check for [a-c-e],
[[:alpha:]-9], [[.a.]-z] — is untouched, and those shapes still error.

New pins in tests/issue1911_ranges.rs (14): multi-range classes in
both orders, range after POSIX class, negated multi-range, three
ranges, -i multi-range, BRE form, matches_entire (find -regex face),
plus the five regression faces above and [a-c-] / []-a].

Refs #1911
UNVERIFIED-BY-CAPTAIN

* fix(od): warn and fall back to the format-size LCM for a non-multiple -w width (#1951)

Refs #1943

* cp: -n is I_ALWAYS_NO per pristine GNU 9.4 (#1879)

-n mapped to Interactive::AlwaysNo (cp.c:1070) instead of the Ubuntu
.deb's silent AlwaysSkip: an existing destination now reports
'not replacing <dst>' and fails the file (copy.c:2438), a fresh copy
under -n prints nothing, and the .deb-only deprecation warning is
gone (no_clobber_seen deleted; make_backups added for the cp.c:1220
--backup/--no-clobber mutual exclusion, set by -b/--backup and
-S/--suffix per cp.c:1027/1191). --update=none keeps the silent
AlwaysSkip form. New i18n keys: command.cp.error.not_replacing,
command.cp.error.backup_and_no_clobber (mv precedent).

Refs #1879 (not Fixes).

* test(gate): cp32/cp34/cp39 record-only — gate GNU side is the patched .deb

The three -n-final rows were calibrated against the WSL distro's
Ubuntu .deb cp 9.4, whose -n is patched to a silent rc-0 skip. The
pristine coreutils 9.4 tarball oracle (this project's standard)
prints "cp: not replacing '<dst>'" and exits 1 for exactly these
combinations (-n, -nv, -nv --update=all, -v -i -n), matching the
port after this PR. The rows stay as record-only (note) so both
sides keep being measured without gating on the .deb divergence.

* fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980)

Refs #1980 (not Fixes).

The --parents intermediate loop walked every '\\' prefix of the
whole destination path, so for a backslash drive-absolute
destination the first prefix created was the bare drive designator
("C:"). Since #1874 a bare "C:" folds to the relative name
"C<U+F03A>" and landed as a stray directory in the cwd — silent
(copy correct, rc 0), and it fired even when no intermediate
directory needed creating, including $TEMP-derived destinations.
GNU's make_dir_parents_private creates only below the destination,
and the destination itself is required to exist (--parents, #1066),
so none of its prefixes ever needs creating here: start the scan
at destPath.size(). The #1874 fold itself is untouched (the
bare-"D:"-is-a-relative-name contract is deliberate).

Pin: cp_parents_backslash_drive_dest_leaves_no_drive_dir — the
reporter's 4-case repro verbatim (backslash drive-absolute dest
with/without trailing backslash, forward-slash control, no
--parents control) plus a $TEMP-derived destination case; each
asserts the copy, rc 0, and that the cwd listing is unchanged.

* fixup: EXPECT_EQ only takes strings in the test framework

The five cwd-listing assertions used EXPECT_EQ on two
std::set<std::string> values; wctest::expect_eq_impl only
accepts strings (C2664 on the x64 default leg). Switch them to
EXPECT_TRUE(set == set). No production code touched.

---------

Co-authored-by: caomengxuan666 <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: dingyi580 <[email protected]>
caomengxuan666 added a commit that referenced this pull request Nov 30, 2026
* test: pin #1874 per-component carrier-colon operand shapes

Fail-first pins for the per-component fold contract: winux-core unit
pins (non-final components, ADS-shaped spellings, mid-path designator
shapes, bare D: as a relative colon name), canon boundary pins through
prepare_operand, and C++ ls/stat applet pins against an on-disk
carrier tree. The bare-D: and canon pins are re-baselined to the
#1874 contract ruled with the rubash #4198 caliber and probed against
Git Bash on a real host.

* fix(path): fold carrier colons per component in both fold twins (#1874)

fold_carrier_colons (winux-core) and fold_carrier_colons_w
(native_path.cppm) encoded only the final component, so operands
with a literal colon in a non-final component (x:y/z, ./x:y/z,
C:\x:y\z) never resolved the carrier tree the shell creates.
Both folds now encode every component, byte-identically: the one
exemption is the path's own drive designator in its absolute form
(D:\ / D:/); a bare D: is a relative colon name and folds like
D:name (MSYS contract, probed against Git Bash); designator-shaped
components mid-path fold as ordinary components; verbatim/device
spellings keep passing through untouched.

* rust2(port+wire): uniq -> rust2 library + bridge (#1488)

* fix(uniq): align open_write_operand and invalid_option signatures

* fix(uniq): use u32 CmdResult and winux_core::test_support in tests

* fix(uniq): fix -1 +1 test assertion and support -D5 cluster digits

* fix(ls): keep printable Unicode literal without POSIX locale (#1883)

Windows filenames cross the narrow boundary as UTF-8 regardless of the
legacy system locale, while interactive ls defaults to shell-escape
quoting. Treating an unset POSIX locale as the C locale made ordinary
CJK names render as octal byte splices for typical Windows users.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(ls): merge adjacent $'...' segments in shell-escape quoting (Fixes #1890)

* fix(ptx): align fallback context truncation to UTF-8 char boundaries

* fix(csplit): preserve trailing literals and UTF-8 in suffix format

* fix(fold): parse numeric width from current index in clustered short options

* fix(od): mask high-order bit in named character output (-a / -t a)

* fix(ptx): slice context and fallback truncations on raw bytes like GNU

* docs: adopt all-contributors, add dingyi580, ShiomiHC, qwased

* fix(canon): realpath -m relative .. ascends from cwd again (Refs #1908) (#1918)

* fix(winux-regex): restore ranges after the first in character classes (#1919)

parse_char_class's is_range required prev_takes_range, so every range
after the first in a bracket expression (or after a POSIX class /
collating element) degraded to literal members: [A-Za-z] lost a-z,
[A-Za-z_]+ silently mis-matched, [[:digit:]a-f] lost a-f. Regression
introduced in 1.2.2 (1.2.1 matches GNU grep 3.12 / sed 4.9).

Drop the prev_takes_range requirement from is_range (one line). The
flag's legitimate use — the Invalid-range-end check for [a-c-e],
[[:alpha:]-9], [[.a.]-z] — is untouched, and those shapes still error.

New pins in tests/issue1911_ranges.rs (14): multi-range classes in
both orders, range after POSIX class, negated multi-range, three
ranges, -i multi-range, BRE form, matches_entire (find -regex face),
plus the five regression faces above and [a-c-] / []-a].

Refs #1911
UNVERIFIED-BY-CAPTAIN

* fix(od): warn and fall back to the format-size LCM for a non-multiple -w width (#1951)

Refs #1943

* cp: -n is I_ALWAYS_NO per pristine GNU 9.4 (#1879)

-n mapped to Interactive::AlwaysNo (cp.c:1070) instead of the Ubuntu
.deb's silent AlwaysSkip: an existing destination now reports
'not replacing <dst>' and fails the file (copy.c:2438), a fresh copy
under -n prints nothing, and the .deb-only deprecation warning is
gone (no_clobber_seen deleted; make_backups added for the cp.c:1220
--backup/--no-clobber mutual exclusion, set by -b/--backup and
-S/--suffix per cp.c:1027/1191). --update=none keeps the silent
AlwaysSkip form. New i18n keys: command.cp.error.not_replacing,
command.cp.error.backup_and_no_clobber (mv precedent).

Refs #1879 (not Fixes).

* test(gate): cp32/cp34/cp39 record-only — gate GNU side is the patched .deb

The three -n-final rows were calibrated against the WSL distro's
Ubuntu .deb cp 9.4, whose -n is patched to a silent rc-0 skip. The
pristine coreutils 9.4 tarball oracle (this project's standard)
prints "cp: not replacing '<dst>'" and exits 1 for exactly these
combinations (-n, -nv, -nv --update=all, -v -i -n), matching the
port after this PR. The rows stay as record-only (note) so both
sides keep being measured without gating on the .deb divergence.

* fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980)

Refs #1980 (not Fixes).

The --parents intermediate loop walked every '\\' prefix of the
whole destination path, so for a backslash drive-absolute
destination the first prefix created was the bare drive designator
("C:"). Since #1874 a bare "C:" folds to the relative name
"C<U+F03A>" and landed as a stray directory in the cwd — silent
(copy correct, rc 0), and it fired even when no intermediate
directory needed creating, including $TEMP-derived destinations.
GNU's make_dir_parents_private creates only below the destination,
and the destination itself is required to exist (--parents, #1066),
so none of its prefixes ever needs creating here: start the scan
at destPath.size(). The #1874 fold itself is untouched (the
bare-"D:"-is-a-relative-name contract is deliberate).

Pin: cp_parents_backslash_drive_dest_leaves_no_drive_dir — the
reporter's 4-case repro verbatim (backslash drive-absolute dest
with/without trailing backslash, forward-slash control, no
--parents control) plus a $TEMP-derived destination case; each
asserts the copy, rc 0, and that the cwd listing is unchanged.

* fixup: EXPECT_EQ only takes strings in the test framework

The five cwd-listing assertions used EXPECT_EQ on two
std::set<std::string> values; wctest::expect_eq_impl only
accepts strings (C2664 on the x64 default leg). Switch them to
EXPECT_TRUE(set == set). No production code touched.

* rust2(port+wire): cat -> rust2 library + bridge (#1488) (#1882)

* rust2(port+wire): cat -> rust2 library + bridge (#1488)

* fix(cat): route /dev/stdin family operands to stdin

* fix(cat): honor WINUX_SHELL_GLOB=done, trailing-slash dir, and dir-on-stdin (#1803)

* fix(ls): keep printable Unicode literal without POSIX locale (#1883)

Windows filenames cross the narrow boundary as UTF-8 regardless of the
legacy system locale, while interactive ls defaults to shell-escape
quoting. Treating an unset POSIX locale as the C locale made ordinary
CJK names render as octal byte splices for typical Windows users.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(ls): merge adjacent $'...' segments in shell-escape quoting (Fixes #1890)

* fix(ptx): align fallback context truncation to UTF-8 char boundaries

* fix(csplit): preserve trailing literals and UTF-8 in suffix format

* fix(fold): parse numeric width from current index in clustered short options

* fix(od): mask high-order bit in named character output (-a / -t a)

* fix(ptx): slice context and fallback truncations on raw bytes like GNU

* docs: adopt all-contributors, add dingyi580, ShiomiHC, qwased

* fix(canon): realpath -m relative .. ascends from cwd again (Refs #1908) (#1918)

* fix(winux-regex): restore ranges after the first in character classes (#1919)

parse_char_class's is_range required prev_takes_range, so every range
after the first in a bracket expression (or after a POSIX class /
collating element) degraded to literal members: [A-Za-z] lost a-z,
[A-Za-z_]+ silently mis-matched, [[:digit:]a-f] lost a-f. Regression
introduced in 1.2.2 (1.2.1 matches GNU grep 3.12 / sed 4.9).

Drop the prev_takes_range requirement from is_range (one line). The
flag's legitimate use — the Invalid-range-end check for [a-c-e],
[[:alpha:]-9], [[.a.]-z] — is untouched, and those shapes still error.

New pins in tests/issue1911_ranges.rs (14): multi-range classes in
both orders, range after POSIX class, negated multi-range, three
ranges, -i multi-range, BRE form, matches_entire (find -regex face),
plus the five regression faces above and [a-c-] / []-a].

Refs #1911
UNVERIFIED-BY-CAPTAIN

* fix(od): warn and fall back to the format-size LCM for a non-multiple -w width (#1951)

Refs #1943

* cp: -n is I_ALWAYS_NO per pristine GNU 9.4 (#1879)

-n mapped to Interactive::AlwaysNo (cp.c:1070) instead of the Ubuntu
.deb's silent AlwaysSkip: an existing destination now reports
'not replacing <dst>' and fails the file (copy.c:2438), a fresh copy
under -n prints nothing, and the .deb-only deprecation warning is
gone (no_clobber_seen deleted; make_backups added for the cp.c:1220
--backup/--no-clobber mutual exclusion, set by -b/--backup and
-S/--suffix per cp.c:1027/1191). --update=none keeps the silent
AlwaysSkip form. New i18n keys: command.cp.error.not_replacing,
command.cp.error.backup_and_no_clobber (mv precedent).

Refs #1879 (not Fixes).

* test(gate): cp32/cp34/cp39 record-only — gate GNU side is the patched .deb

The three -n-final rows were calibrated against the WSL distro's
Ubuntu .deb cp 9.4, whose -n is patched to a silent rc-0 skip. The
pristine coreutils 9.4 tarball oracle (this project's standard)
prints "cp: not replacing '<dst>'" and exits 1 for exactly these
combinations (-n, -nv, -nv --update=all, -v -i -n), matching the
port after this PR. The rows stay as record-only (note) so both
sides keep being measured without gating on the .deb divergence.

* fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980)

Refs #1980 (not Fixes).

The --parents intermediate loop walked every '\\' prefix of the
whole destination path, so for a backslash drive-absolute
destination the first prefix created was the bare drive designator
("C:"). Since #1874 a bare "C:" folds to the relative name
"C<U+F03A>" and landed as a stray directory in the cwd — silent
(copy correct, rc 0), and it fired even when no intermediate
directory needed creating, including $TEMP-derived destinations.
GNU's make_dir_parents_private creates only below the destination,
and the destination itself is required to exist (--parents, #1066),
so none of its prefixes ever needs creating here: start the scan
at destPath.size(). The #1874 fold itself is untouched (the
bare-"D:"-is-a-relative-name contract is deliberate).

Pin: cp_parents_backslash_drive_dest_leaves_no_drive_dir — the
reporter's 4-case repro verbatim (backslash drive-absolute dest
with/without trailing backslash, forward-slash control, no
--parents control) plus a $TEMP-derived destination case; each
asserts the copy, rc 0, and that the cwd listing is unchanged.

* fixup: EXPECT_EQ only takes strings in the test framework

The five cwd-listing assertions used EXPECT_EQ on two
std::set<std::string> values; wctest::expect_eq_impl only
accepts strings (C2664 on the x64 default leg). Switch them to
EXPECT_TRUE(set == set). No production code touched.

---------

Co-authored-by: caomengxuan666 <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: dingyi580 <[email protected]>

---------

Co-authored-by: caomengxuan666 <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: dingyi580 <[email protected]>
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.

1 participant