mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
terminal: osc parser gracefully handles input data larger than buffer
This commit is contained in:
@ -149,6 +149,12 @@ pub const Parser = struct {
|
|||||||
|
|
||||||
/// Consume the next character c and advance the parser state.
|
/// Consume the next character c and advance the parser state.
|
||||||
pub fn next(self: *Parser, c: u8) void {
|
pub fn next(self: *Parser, c: u8) void {
|
||||||
|
// If our buffer is full then we're invalid.
|
||||||
|
if (self.buf_idx >= self.buf.len) {
|
||||||
|
self.state = .invalid;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// We store everything in the buffer so we can do a better job
|
// We store everything in the buffer so we can do a better job
|
||||||
// logging if we get to an invalid command.
|
// logging if we get to an invalid command.
|
||||||
self.buf[self.buf_idx] = c;
|
self.buf[self.buf_idx] = c;
|
||||||
@ -498,3 +504,14 @@ test "OSC: get/set clipboard" {
|
|||||||
try testing.expect(cmd.clipboard_contents.kind == 's');
|
try testing.expect(cmd.clipboard_contents.kind == 's');
|
||||||
try testing.expect(std.mem.eql(u8, "?", cmd.clipboard_contents.data));
|
try testing.expect(std.mem.eql(u8, "?", cmd.clipboard_contents.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "OSC: longer than buffer" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
var p: Parser = .{};
|
||||||
|
|
||||||
|
const input = "a" ** (Parser.MAX_BUF + 2);
|
||||||
|
for (input) |ch| p.next(ch);
|
||||||
|
|
||||||
|
try testing.expect(p.end() == null);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user