libghostty_vt/paste.rs
1//! Utilities for validating paste data safety.
2//!
3//! # Example
4//!
5//! ```rust
6//! use libghostty_vt::paste;
7//!
8//! let safe_data = "hello world";
9//! let unsafe_data = "rm -rf /\n";
10//!
11//! if paste::is_safe(safe_data) {
12//! println!("Safe to paste");
13//! }
14//!
15//! if !paste::is_safe(unsafe_data) {
16//! println!("Unsafe! Contains newline");
17//! }
18//! ```
19
20use crate::ffi;
21
22/// Check if paste data is safe to paste into the terminal.
23///
24/// Data is considered unsafe if it contains:
25/// * Newlines (`\n`) which can inject commands
26/// * The bracketed paste end sequence (`\x1b[201~`) which can be used to exit bracketed paste
27/// mode and inject commands
28///
29/// This check is conservative and considers data unsafe regardless of current terminal state.
30#[must_use]
31pub fn is_safe(data: &str) -> bool {
32 unsafe { ffi::ghostty_paste_is_safe(data.as_ptr().cast(), data.len()) }
33}