Skip to content

fix(ptx): slice context and fallback truncations on raw bytes like GNU - #1894

Merged
caomengxuan666 merged 2 commits into
unixwin:mainfrom
dingyi580:fix/ptx-utf8-truncation-boundary
Nov 27, 2026
Merged

caomengxuan666 merged 2 commits into
unixwin:mainfrom
dingyi580:fix/ptx-utf8-truncation-boundary

Conversation

@dingyi580

@dingyi580 dingyi580 commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

  • Keep input text, sort keys, and field truncation buffers in ptx as raw byte slices (Vec<u8> / &[u8]) instead of UTF-8 String slicing, matching GNU coreutils ptx (9.4) and the retired C++ ptx pipeline byte-for-byte on non-whitespace fallback truncations.
  • Eliminates runtime UTF-8 boundary panics when value.len() - limit or limit lands mid-codepoint while preserving GNU's raw partial-UTF-8 byte truncation behavior (e.g. hello\xe2/ under -w 16 and /\x96\x87\xe2\x80\x94 hello under -w 20).
  • No user-visible I18N catalog strings (tr!) are modified.

What was removed

  • Removed lossy String conversion (from_utf8_lossy) on source input and UTF-8 character-boundary clamping in rightmost_field / leftmost_field.

Verification

  • rustfmt --check --edition 2021 rust2/crates/winux-cmds/src/ptx.rs: passed
  • cargo check --workspace --tests --target x86_64-pc-windows-msvc & aarch64-pc-windows-msvc: passed
  • Unit tests (ptx::tests, including utf8_multibyte_truncation_slices_raw_bytes_like_gnu probed against GNU ptx): 10 passed, 0 failed

@caomengxuan666

Copy link
Copy Markdown
Member

CAPTAIN-VERIFY(X299 运行时复验):仍需返工(一项真分歧)。

已过面:lib 1092/0、新钉实跑绿、原 panic 消除(driver 7 例全 rc=0)。

R1 无空白回退截断须按字节对齐 GNU:oracle(云端 GNU coreutils 9.4)逐字节差分 0/7——在无空白可断的回退截断路径上,GNU 按字节截断(C 与 C.UTF-8 locale 同形,输出可含残缺 UTF-8 字节),本 PR 改后按字符边界截断;PR 断言中的 hello/、/— hello 是实现自洽串、非 GNU 串(GNU 原例输出并不含此二子串)。队长裁决:按 GNU 字节口径返工——回退截断按字节切、断言改为 GNU 实测串;这与本仓一贯的逐字节对齐口径一致,不作有意分歧处理。返工后队长在 X299 复跑差分 7 例终裁。

@dingyi580 dingyi580 changed the title fix(ptx): align fallback context truncation to UTF-8 char boundaries fix(ptx): slice context and fallback truncations on raw bytes like GNU Nov 27, 2026
@dingyi580

Copy link
Copy Markdown
Author

已按 CAPTAIN-VERIFY R1 要求返工完成:

  • 将 ptx 输入缓冲、词元索引与 rightmost_field / leftmost_field / emit_*_line 全链路改为原始字节切片(&[u8] / Vec<u8>),移除 from_utf8_lossy 与 is_char_boundary 字符边界对齐,无空白回退截断按原始字节硬切输出,与 GNU coreutils ptx 字节口径一致(既消除原 UTF-8 切片 panic,又保留残缺 UTF-8 字节输出)。
  • 回归测试 utf8_multibyte_truncation_slices_raw_bytes_like_gnu 已切换为 GNU ptx 实测字节断言(如 -w 14 b"hello/"、-w 16 b"hello\xe2/"、-w 18 b"hello\xe2\x80/",以及前向截断 -w 18 b"/\x87\xe2\x80\x94 hello"、-w 20 b"/\x96\x87\xe2\x80\x94 hello"),本地 10/10 单元钉实跑全绿,双架构 MSVC check 与 rustfmt --check 通过。请队长复验!

@caomengxuan666

Copy link
Copy Markdown
Member

CAPTAIN-VERIFY(只读复核,新 head 243be8dd):达合入门(只读,待运行时)。返工提交只改 ptx.rs 一文件、无搭车:is_char_boundary 循环已删、整路改 Vec<u8> 字节口径;新断言五形逐项算过账,其中 -w 16 的 hello\xe2/ 与 rt4 oracle 实录逐字吻合。新 head CI 全绿(构建 4/4、rust-tests、i18n-drift、gate 全分片、GNU 差分)。待补运行时:X299 上 oracle 7 例 + 新断言 5 形差分重跑、lib 1092/0、fail-first 抽查,过后终裁。

@caomengxuan666

Copy link
Copy Markdown
Member

CAPTAIN-VERIFY(X299 运行时复验):达合入门,队长合入。

本 PR 的返工项 R1(回退截断按字节对齐 GNU)全证闭合:截断内容面与 GNU coreutils 9.4 逐字全合(hello\xe2/、/\x87\xe2\x80\x94 hello 等残缺 UTF-8 形全对,新断言 5 形均为 GNU 实测串)、lib 1092/0、新钉 utf8_multibyte_truncation_slices_raw_bytes_like_gnu 逐名 ok、fail-first 双向成立。

同时说明 oracle 全行逐字节仍 0/12 的原因:rt4 的 0/7 实为两层分歧叠加,第二层是先存的 ptx 布局分歧(关键字列宽公式、小宽关键字截断、上下文回绕),经核 base 363d7a0c 与本 head 布局代码逐行相同、源于已合入的移植本体、本 PR 两提交均未触。队长裁:该层另立 #1906 跟踪,不并入本 PR——本 PR 范围(截断字节口径)已全证,不因 base 先存面扣留。

@caomengxuan666
caomengxuan666 merged commit c96b8c3 into unixwin:main Nov 27, 2026
32 checks passed
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.

2 participants