Replies: 1 comment
|
Confirmed and reproduced from your example path, and your root-cause analysis is exactly right. A UTF-16LE terminator is a whole code unit, so both bytes must be zero. Testing only the low byte mistakes any character encoded Fixwhile (end + 1 < bytes.length && bytes.readUInt16LE(end) !== 0) end += 2The existing loop guard Why the existing tests could never have caught itThis is the part worth recording. The package's suite has driven a CJK path since it was written — The regression test needs a character that specifically has a zero low byte. #4654 reports the same defect with a good second example: Scope checkI swept the tree for the same class while I was in there: this is the only place a NUL terminator is located by scanning. #4648 is the same root cause seen from the outside — a folder mixing English and Chinese that simply cannot be selected as a workspace — so all three reports collapse to this one line. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary / 概述
On Windows, when adding a workspace through the native folder picker, the picked
path is read by
readUtf16()inpackages/dsh-host-directory-picker-native(lib/worker.cjs). Its end-of-stringtest only checks the low byte of each UTF-16LE code unit:
For any CJK character whose UTF-16LE encoding has a low byte of
0x00— e.g."一" (U+4E00, encoded
00 4E) — the loop stops early and the path istruncated at that character.
fs.realpaththen fails with ENOENT and theworkspace cannot be created ("file does not exist", path shown truncated).
中文:Windows 上通过原生文件夹对话框添加工作区时,
readUtf16()判断字符串结尾只检查 UTF-16LE 的低字节。路径中含有"一"(U+4E00,编码
00 4E,低字节为0x00)等汉字时,循环提前终止,路径被截断,
fs.realpath报 ENOENT,工作区创建失败,错误信息里路径也显示为截断后的样子。
Environment / 环境
(
@deepseek-ai/dsh-host-directory-picker-native) — auto-resolved whenbound to 127.0.0.1 on win32 without SSH.
packages/dsh-host-directory-picker-native/src/types/win32-dialog-bindings.ts(built output
lib/worker.cjs, functionreadUtf16, line ~21-26).Steps to reproduce / 复现步骤
dsh web(bound to 127.0.0.1), open the browser UI.byte 0x00, e.g.
D:\repro\检测工程参数是否一致(the 9th char "一" is U+4E00).
The path is truncated:
检测工程参数是否一致(10 chars) became检测工程参数是否(8 chars) — "一致" is lost. Any path containing "一" (U+4E00)or similar (low byte 0x00) triggers this.
Root cause / 根因
readUtf16scans a UTF-16LE buffer for the NUL terminator but tests onlybytes[end] !== 0(the low byte). UTF-16LE encodes U+4E00 as bytes00 4E;the low byte
0x00is mistaken for the string terminator, so scanning stopsmid-character and the returned path is truncated.
Verification (Node):
Suggested fix / 修复建议
Test the full 16-bit code unit (both bytes) for NUL:
With the fix, all tested cases pass, including "一致" in the middle or at the
end of the path. (A patch script for the built
worker.cjsis available; happyto share if useful.)
Impact / 影响范围
0x00(e.g. 一 U+4E00, and other CJK chars in the 0x00xx range of the lowbyte) cannot be picked via the native Windows folder dialog.
truncation is silent until
realpathfails — confusing for users.dsh-host-directory-picker-browse) is NOT affected(uses Node fs dirent names directly).
All reactions