fix decoding invalid UTF-8 input (#3563)

* fix decoding invalid UTF-8 input
Close: https://github.com/oven-sh/bun/issues/3562

* add unittest
This commit is contained in:
Ai Hoshino
2023-07-08 06:10:49 +08:00
committed by GitHub
parent affd06d05c
commit c0cf7b4501
2 changed files with 11 additions and 2 deletions

View File

@@ -241,3 +241,12 @@ for (const StringDecoder of [FakeStringDecoderCall, RealStringDecoder]) {
});
});
}
it("invalid utf-8 input, pr #3562", () => {
const decoder = new RealStringDecoder("utf-8");
let output = "";
output += decoder.write(Buffer.from("B9", "hex"));
output += decoder.write(Buffer.from("A9", "hex"));
output += decoder.end();
expect(output).toStrictEqual("\uFFFD\uFFFD");
});