diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 3c41274e46..cf43e1f43c 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -5808,15 +5808,16 @@ pub const visible = struct { var len: usize = 0; while (bun.strings.firstNonASCII(bytes)) |i| { len += asciiFn(bytes[0..i]); + const this_chunk = bytes[i..]; + const byte = this_chunk[0]; - const byte = bytes[i]; const skip = bun.strings.wtf8ByteSequenceLengthWithInvalid(byte); - const cp_bytes: [4]u8 = switch (skip) { + const cp_bytes: [4]u8 = switch (@min(@as(usize, skip), this_chunk.len)) { inline 1, 2, 3, 4 => |cp_len| .{ byte, - if (comptime cp_len > 1) bytes[1] else 0, - if (comptime cp_len > 2) bytes[2] else 0, - if (comptime cp_len > 3) bytes[3] else 0, + if (comptime cp_len > 1) this_chunk[1] else 0, + if (comptime cp_len > 2) this_chunk[2] else 0, + if (comptime cp_len > 3) this_chunk[3] else 0, }, else => unreachable, }; diff --git a/test/js/bun/console/__snapshots__/console-table.test.ts.snap b/test/js/bun/console/__snapshots__/console-table.test.ts.snap index beda30eb39..83bf72ab2b 100644 --- a/test/js/bun/console/__snapshots__/console-table.test.ts.snap +++ b/test/js/bun/console/__snapshots__/console-table.test.ts.snap @@ -185,3 +185,12 @@ exports[`console.table ansi colors 1`] = ` └───────┴─────────────────────────────────────────────┘ " `; + +exports[`console.table expected output for: properties - interesting character 1`] = ` +"┌───┬────────┐ +│ │ Values │ +├───┼────────┤ +│ a │ _字 │ +└───┴────────┘ +" +`; diff --git a/test/js/bun/console/console-table.test.ts b/test/js/bun/console/console-table.test.ts index 5da7983483..0841aa9e0d 100644 --- a/test/js/bun/console/console-table.test.ts +++ b/test/js/bun/console/console-table.test.ts @@ -95,6 +95,16 @@ describe("console.table", () => { args: () => [[{ a: 42, b: "bun" }], []], }, ], + [ + "properties - interesting character", + { + args: () => [ + { + a: "_字", + }, + ], + }, + ], [ "values - array", {