mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
kitty: fix crash when no keys provided
This commit is contained in:
@ -227,7 +227,10 @@ pub const Parser = struct {
|
|||||||
complete: bool = false,
|
complete: bool = false,
|
||||||
|
|
||||||
/// Temporary state that is dependent on the current state.
|
/// Temporary state that is dependent on the current state.
|
||||||
temp_state: union {
|
temp_state: union(enum) {
|
||||||
|
/// Default empty state
|
||||||
|
empty: void,
|
||||||
|
|
||||||
/// Current string parameter being populated
|
/// Current string parameter being populated
|
||||||
str: *[]const u8,
|
str: *[]const u8,
|
||||||
|
|
||||||
@ -236,7 +239,7 @@ pub const Parser = struct {
|
|||||||
|
|
||||||
/// Temporary state for key/value pairs
|
/// Temporary state for key/value pairs
|
||||||
key: []const u8,
|
key: []const u8,
|
||||||
} = undefined,
|
} = .{ .empty = {} },
|
||||||
|
|
||||||
// Maximum length of a single OSC command. This is the full OSC command
|
// Maximum length of a single OSC command. This is the full OSC command
|
||||||
// sequence length (excluding ESC ]). This is arbitrary, I couldn't find
|
// sequence length (excluding ESC ]). This is arbitrary, I couldn't find
|
||||||
@ -342,6 +345,7 @@ pub const Parser = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.state = .empty;
|
self.state = .empty;
|
||||||
|
self.temp_state = .{ .empty = {} };
|
||||||
self.buf_start = 0;
|
self.buf_start = 0;
|
||||||
self.buf_idx = 0;
|
self.buf_idx = 0;
|
||||||
self.complete = false;
|
self.complete = false;
|
||||||
@ -1011,15 +1015,25 @@ pub const Parser = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn endKittyColorProtocolOption(self: *Parser, kind: enum { key_only, key_and_value }, final: bool) void {
|
fn endKittyColorProtocolOption(self: *Parser, kind: enum { key_only, key_and_value }, final: bool) void {
|
||||||
|
const key = key: {
|
||||||
|
switch (self.temp_state) {
|
||||||
|
.key => {
|
||||||
if (self.temp_state.key.len == 0) {
|
if (self.temp_state.key.len == 0) {
|
||||||
log.warn("zero length key in kitty color protocol", .{});
|
log.warn("zero length key in kitty color protocol", .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = kitty.color.Kind.parse(self.temp_state.key) orelse {
|
break :key kitty.color.Kind.parse(self.temp_state.key) orelse {
|
||||||
log.warn("unknown key in kitty color protocol: {s}", .{self.temp_state.key});
|
log.warn("unknown key in kitty color protocol: {s}", .{self.temp_state.key});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
else => {
|
||||||
|
log.warn("no key in kitty color protocol", .{});
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const value = value: {
|
const value = value: {
|
||||||
if (self.buf_start == self.buf_idx) break :value "";
|
if (self.buf_start == self.buf_idx) break :value "";
|
||||||
@ -1730,3 +1744,17 @@ test "OSC: kitty color protocol double reset" {
|
|||||||
p.reset();
|
p.reset();
|
||||||
p.reset();
|
p.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "OSC: kitty color protocol no key" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
var p: Parser = .{ .alloc = testing.allocator };
|
||||||
|
defer p.deinit();
|
||||||
|
|
||||||
|
const input = "21;";
|
||||||
|
for (input) |ch| p.next(ch);
|
||||||
|
|
||||||
|
const cmd = p.end('\x1b').?;
|
||||||
|
try testing.expect(cmd == .kitty_color_protocol);
|
||||||
|
try testing.expectEqual(0, cmd.kitty_color_protocol.list.items.len);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user