From 254365afab7eb2c1cd504e468eb9d22d37770f1f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 4 Nov 2023 11:25:02 -0700 Subject: [PATCH] terminal: add sanitize.zig --- src/terminal/sanitize.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/terminal/sanitize.zig diff --git a/src/terminal/sanitize.zig b/src/terminal/sanitize.zig new file mode 100644 index 000000000..f492291aa --- /dev/null +++ b/src/terminal/sanitize.zig @@ -0,0 +1,13 @@ +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; +} + +test isSafePaste { + const testing = std.testing; + try testing.expect(isSafePaste("hello")); + try testing.expect(!isSafePaste("hello\n")); + try testing.expect(!isSafePaste("hello\nworld")); +}