You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
环境
问题描述
在网页端点击「添加工作区」并通过系统文件夹选择框选中一个名字里含「开」字的文件夹后,
返回的路径被截断,导致创建工作区失败,报错:
workspace-invalid-path: cannot create a workspace at "D:\A-游戏":
ENOENT: no such file or directory, realpath 'D:\A-游戏'
正确路径是 D:\A-游戏开发,但实际传入的路径变成了 D:\A-游戏,「开发」两个字被截掉了,
所以 fs.realpath 找不到这个不存在的路径。
复现步骤
根本原因
lib/worker.cjs 中的 readUtf16 函数通过「只检查每个 UTF-16 码元的低字节是否为 0」
来判断字符串是否结束:
而「开」(U+5F00)的 UTF-16LE 编码是 00 5F,低字节恰好是 0x00,于是被误判为
字符串结束符(NUL),路径在这个字符处被截断。
最小复现(Node.js)
const name = "D:\A-\u6E38\u620F\u5F00\u53D1"; // 即 A-游戏开发
const buf = Buffer.from(name, "utf16le");
let end = 0;
while (end + 1 < buf.length && buf[end] !== 0) end += 2;
console.log(buf.toString("utf16le", 0, end)); // 输出 "D:\A-游戏"
建议修复
判断结束时应检查整个 16 位码元是否为 0,例如:
或者更直观地使用:
影响范围
凡是 Unicode 编码以 00 结尾的汉字都会触发,常见如:
「一」(U+4E00)、「开」(U+5F00)、「刀」(U+5200)、「怀」(U+6000)、「最」(U+6700)、
「耀」(U+8000) 等。任何含这些字的文件夹路径都会被截断,属于影响中文用户的高频问题。
All reactions