mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
fix assert() crash (#1941)
This commit is contained in:
@@ -1419,7 +1419,7 @@ pub fn convertUTF8BytesIntoUTF16(sequence: *const [4]u8) UTF16Replacement {
|
||||
switch (len) {
|
||||
2 => {
|
||||
if (Environment.allow_assert)
|
||||
assert(sequence[0] >= 0xC2);
|
||||
assert(sequence[0] >= 0xC0);
|
||||
if (Environment.allow_assert)
|
||||
assert(sequence[0] <= 0xDF);
|
||||
if (sequence[1] < 0x80 or sequence[1] > 0xBF) {
|
||||
|
||||
@@ -2813,3 +2813,11 @@ test("Buffer.byteLength", () => {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("should not crash on invalid UTF-8 byte sequence", () => {
|
||||
const buf = Buffer.from([0xC0, 0xFD]).toString();
|
||||
expect(buf.length).toBe(2);
|
||||
const str = buf.toString();
|
||||
expect(str.length).toBe(2);
|
||||
expect(str).toBe("\uFFFD\uFFFD");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user