unexpand: final newline prevents conversion of leading Unicode blanks
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #15925 来自 @Ybucaille —— 已合并
评估
调研方向
从src/uu/unexpand/src/unexpand.rs中unexpand_buf的快速路径(约第512–523行)开始,追踪它在处理 Unicode 空白之前如何处理以换行符结尾的输入。使用 issue 中的命令复现,并比较默认模式与-a;当默认模式将开头的 U+3000 字符转换为一个制表符并保留末尾换行符,且相关的 unexpand 测试通过时,即为完成。
由索引模型根据 Issue 内容生成。
描述
In a UTF-8 locale, unexpand leaves leading Unicode blanks unchanged when the line ends in a newline. Removing that newline makes the same blanks convert to a tab. GNU coreutils 9.12 converts them in both cases.
Reproduced on main c1f172886c6643f61ffde5a1ce3db0aaf14e182b on Linux, in both debug and release builds:
python3 -c 'print("\u3000" * 4 + "X")' |
LC_ALL=C.UTF-8 coreutils unexpand | od -An -tx1
The input is four U+3000 IDEOGRAPHIC SPACE characters (eight display columns), followed by X and a newline.
Expected, as printed by GNU unexpand 9.12:
09 58 0a
Actual:
e3 80 80 e3 80 80 e3 80 80 e3 80 80 58 0a
The same command with unexpand -a produces the expected tab. So does default unexpand if the final newline is omitted. --first-only has the same failure as default mode.
The first fast path in unexpand_buf (src/uu/unexpand/src/unexpand.rs:512-523) checks only for ASCII space and tab before copying a newline-terminated buffer unchanged. This bypasses the Unicode blank handling later in the function.
I compared 416 cases against GNU 9.12 across 13 Unicode blank characters, two UTF-8 locales, file/pipe input, with/without a final newline, and four option sets. Both uutils builds had the same 104 mismatches, all in default/--first-only mode with a final newline. All 44 existing unexpand integration tests pass.
- 主要语言
- Rust
- 星标
- 24.3k
- 派生
- 2.1k
- 平均合并
- 1 天 21 小时
- 30 天内合并 PR
- 360
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
uutils/coreutils 的其他 Issue
-
ls: `--block-size=0` is accepted when `--si` comes later可能已有人在做 @Logic769 于 1 天前认领。 未关闭good first issue U - ls
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
uutils/coreutils#15962 · 3 条评论 ·
维护者通常 1 天内回复
-
B - high priority U - tr
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
U - df
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
mv: a failed cross-device move always reports "Permission denied"可能已有人在做 @afnan-mojumder 今天认领。 未关闭U - mv
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
calcit-lang/caps#16 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
penso/herdr-gpui#934 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
Y-ASLant/ElegantClipboard#178 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
linxiv-dev/linXiv#384 · 1 条评论 ·
维护者通常 1 天内回复
-
priority middle
难度 2/5 1-3 小时 新手友好度 70/100
KATO-Hiro/AtCoderClans#12945 ·
维护者通常 1 天内回复