mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-09 15:58:34 +00:00
fix MobaXterm Chinese import encoding
This commit is contained in:
@@ -24,3 +24,27 @@ test("readTextFile decodes UTF-16 BE with BOM", async () => {
|
||||
const file = new File([bytes], "note.md", { type: "text/plain" });
|
||||
assert.equal(await readTextFile(file), "hi");
|
||||
});
|
||||
|
||||
test("readTextFile uses the fallback encoding for non-UTF-8 text without a BOM", async () => {
|
||||
const bytes = new Uint8Array([
|
||||
0x5b, 0x42, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x5d, 0x0a,
|
||||
0xd6, 0xd0, 0xce, 0xc4, 0xb7, 0xfe, 0xce, 0xf1, 0xc6, 0xf7,
|
||||
]);
|
||||
const file = new File([bytes], "MobaXterm.ini", { type: "text/plain" });
|
||||
|
||||
assert.equal(
|
||||
await readTextFile(file, { fallbackEncoding: "gb18030" }),
|
||||
"[Bookmarks]\n中文服务器",
|
||||
);
|
||||
});
|
||||
|
||||
test("readTextFile keeps valid UTF-8 when a fallback encoding is configured", async () => {
|
||||
const file = new File(["[Bookmarks]\n中文服务器"], "MobaXterm.ini", {
|
||||
type: "text/plain",
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
await readTextFile(file, { fallbackEncoding: "gb18030" }),
|
||||
"[Bookmarks]\n中文服务器",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user