[Bug报告] 工作区选择器在"阀"(U+9600) 处截断所选路径(低位字节为 0 的字符均受影响) #3442
Replies: 1 comment
|
Confirmed — this is the 4th report of the same bug, and your root cause + fix + test are exactly right. Family closure: The readUtf16 low-byte truncation family (4 reports)
Your diagnosis matches the canonical one from #3291 (verified at source + empirically reproduced in node): On your fixYour negated-both-bytes form: while (end + 1 < bytes.length && !(bytes[end] === 0 && bytes[end + 1] === 0)) end += 2is equivalent to the The regression test is the critical part — and your fixture ( Suggested PR shape (when the channel reopens)This is the cleanest small fix in the queue: 1 line in One note for the maintainers: consider a sweep for other |
Uh oh!
There was an error while loading. Please reload this page.
[Bug] 工作区选择器在"阀"(U+9600) 处截断所选路径
环境:Windows +
dsh web(0.1.0-rc.5),通过原生 Win32 文件夹选择器(host.pickDirectory)选择工作区。复现步骤:
D:\data\疏水阀数据\2025年;预期结果:注册的工作区路径等于所选完整路径。
实际结果:路径在第一个"阀"字处被截断——显示为
D:\data\疏水,"阀"及其后所有内容全部丢失。根因:
packages/host/directory-picker-native/src/win32-dialog-bindings.ts的readUtf16在查找 UTF-16 字符串的 NUL 终止符时,只检查每个编码单元的低位字节:任何码点为 0x100 整数倍的 BMP 字符,其 UTF-16LE 编码的低位字节都是 0x00——例如 阀 (U+9600)、退 (U+9000)、耀 (U+8000)、怀 (U+6000)——扫描会在这里提前结束,该字符及其后的路径内容被丢弃。这正是阀门/蒸汽类数据的目录名含"阀"时必然触发的原因。
修复方案:改为检查完整的 16 位编码单元(Windows 路径不可能包含 U+0000,因此该判断是安全的):
回归测试:已在
tests/win32-dialog-bindings.spec.ts中加入含"阀"路径的用例(C:\疏水阀数据\2025年\子目录),包内测试全部通过(13 个)。All reactions