terminal: ignore change window title requests with invalid UTF-8

This commit is contained in:
Mitchell Hashimoto
2024-01-23 11:52:56 -08:00
parent 0a47224a4e
commit f445ee269f

View File

@ -978,6 +978,11 @@ pub fn Stream(comptime Handler: type) type {
switch (cmd) { switch (cmd) {
.change_window_title => |title| { .change_window_title => |title| {
if (@hasDecl(T, "changeWindowTitle")) { if (@hasDecl(T, "changeWindowTitle")) {
if (!std.unicode.utf8ValidateSlice(title)) {
log.warn("change title request: invalid utf-8, ignoring request", .{});
return;
}
try self.handler.changeWindowTitle(title); try self.handler.changeWindowTitle(title);
return; return;
} else log.warn("unimplemented OSC callback: {}", .{cmd}); } else log.warn("unimplemented OSC callback: {}", .{cmd});
@ -1627,6 +1632,30 @@ test "stream: XTSHIFTESCAPE" {
try testing.expect(s.handler.escape.? == true); try testing.expect(s.handler.escape.? == true);
} }
test "stream: change window title with invalid utf-8" {
const H = struct {
seen: bool = false,
pub fn changeWindowTitle(self: *@This(), title: []const u8) !void {
_ = title;
self.seen = true;
}
};
{
var s: Stream(H) = .{ .handler = .{} };
try s.nextSlice("\x1b]2;abc\x1b\\");
try testing.expect(s.handler.seen);
}
{
var s: Stream(H) = .{ .handler = .{} };
try s.nextSlice("\x1b]2;abc\xc0\x1b\\");
try testing.expect(!s.handler.seen);
}
}
test "stream: insert characters" { test "stream: insert characters" {
const H = struct { const H = struct {
const Self = @This(); const Self = @This();