Files
ghostty/src/terminal/c/paste.zig
2026-03-25 07:28:22 -07:00

38 lines
1.0 KiB
Zig

const std = @import("std");
const lib = @import("../lib.zig");
const paste = @import("../../input/paste.zig");
pub fn is_safe(data: ?[*]const u8, len: usize) callconv(lib.calling_conv) bool {
const slice: []const u8 = if (data) |v| v[0..len] else &.{};
return paste.isSafe(slice);
}
test "is_safe with safe data" {
const testing = std.testing;
const safe = "hello world";
try testing.expect(is_safe(safe.ptr, safe.len));
}
test "is_safe with newline" {
const testing = std.testing;
const unsafe = "hello\nworld";
try testing.expect(!is_safe(unsafe.ptr, unsafe.len));
}
test "is_safe with bracketed paste end" {
const testing = std.testing;
const unsafe = "hello\x1b[201~world";
try testing.expect(!is_safe(unsafe.ptr, unsafe.len));
}
test "is_safe with empty data" {
const testing = std.testing;
const empty = "";
try testing.expect(is_safe(empty.ptr, 0));
}
test "is_safe with null empty data" {
const testing = std.testing;
try testing.expect(is_safe(null, 0));
}