terminal: sgr direct color fg missing color doesn't crash

This commit is contained in:
Mitchell Hashimoto
2023-10-27 09:25:16 -07:00
parent 0b6cbfa141
commit d28e6739c7

View File

@ -197,7 +197,7 @@ pub const Parser = struct {
.b = @truncate(rgb[2]),
},
};
} else if (slice.len >= 2 and slice[1] == 5) {
} else if (slice.len >= 3 and slice[1] == 5) {
self.idx += 2;
return Attribute{
.@"256_fg" = @truncate(slice[2]),
@ -532,3 +532,9 @@ test "sgr: underline, bg, and fg" {
try testing.expectEqual(Attribute.Underline.single, v.underline);
}
}
test "sgr: direct color fg missing color" {
// This used to crash
var p: Parser = .{ .params = &[_]u16{ 38, 5 }, .colon = false };
while (p.next()) |_| {}
}