ghostty/src/terminal/sanitize.zig
Mitchell Hashimoto fb7cbd69c0 core: consider any paste with bracketed paste closer unsafe
Thanks to: https://thejh.net/misc/website-terminal-copy-paste

If a paste has the ending sentinel value for a bracketed paste
("\x1b[201~") then the shell may start processing data faster. We now
consider this unsafe even if the `clipboard-paste-bracketed-safe`
setting is true.
2024-06-08 14:38:49 -07:00

15 lines
440 B
Zig

const std = @import("std");
/// Returns true if the data looks safe to paste.
pub fn isSafePaste(data: []const u8) bool {
return std.mem.indexOf(u8, data, "\n") == null and
std.mem.indexOf(u8, data, "\x1b[201~") == null;
}
test isSafePaste {
const testing = std.testing;
try testing.expect(isSafePaste("hello"));
try testing.expect(!isSafePaste("hello\n"));
try testing.expect(!isSafePaste("hello\nworld"));
}