mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-19 10:16:12 +03:00
zero-width chars are ignored if they're at col 0
This can cause a crash, and is impossible since zero-width chars are always attached to a prior character. Word-wrapping doesn't come into play here because this check happens prior to the wrapping.
This commit is contained in:
@ -566,6 +566,15 @@ pub fn print(self: *Terminal, c: u21) !void {
|
||||
|
||||
// Attach zero-width characters to our cell as grapheme data.
|
||||
if (width == 0) {
|
||||
// If we're at cell zero, then this is malformed data and we don't
|
||||
// print anything or even store this. Zero-width characters are ALWAYS
|
||||
// attached to some other non-zero-width character at the time of
|
||||
// writing.
|
||||
if (self.screen.cursor.x == 0) {
|
||||
log.warn("zero-width character with no prior character, ignoring", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
// Find our previous cell
|
||||
const row = self.screen.getRow(.{ .active = self.screen.cursor.y });
|
||||
const prev: usize = prev: {
|
||||
@ -1391,6 +1400,18 @@ test "Terminal: input with no control characters" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Terminal: zero-width character at start" {
|
||||
var t = try init(testing.allocator, 80, 80);
|
||||
defer t.deinit(testing.allocator);
|
||||
|
||||
// This used to crash the terminal. This is not allowed so we should
|
||||
// just ignore it.
|
||||
try t.print(0x200D);
|
||||
|
||||
try testing.expectEqual(@as(usize, 0), t.screen.cursor.y);
|
||||
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
||||
}
|
||||
|
||||
test "Terminal: soft wrap" {
|
||||
var t = try init(testing.allocator, 3, 80);
|
||||
defer t.deinit(testing.allocator);
|
||||
|
Reference in New Issue
Block a user