pub struct PathSanitizer;Expand description
Sanitizes dropped payloads, decoding RFC 8089 file URIs, percent-encoded bytes, and shell-escaped file paths into valid OS PathBuf representations.
Implementations§
Source§impl PathSanitizer
impl PathSanitizer
Sourcepub fn parse_drop_payload(payload: &str) -> Vec<PathBuf>
pub fn parse_drop_payload(payload: &str) -> Vec<PathBuf>
Parses a raw drag-and-drop payload string (which may contain multiple lines and file:// URI schemes) into sanitized PathBuf instances.
Sourcepub fn looks_like_drop(payload: &str) -> bool
pub fn looks_like_drop(payload: &str) -> bool
Heuristic classifier: does payload look like a file drag-and-drop rather than
ordinary pasted text? Returns true when it uses the file:// scheme, or when every
non-empty line is shaped like a filesystem path (/…, ~/…, ./…, ../…, or a
Windows drive path like C:\…).
This is purely syntactic — it never touches the filesystem, so it stays
deterministic and testable. A terminal delivers both a real drop and a normal paste
as Event::Paste, so use this to decide whether to route a payload through
parse_drop_payload; because a path-shaped line of prose
can still slip through, callers wanting certainty should confirm the parsed paths
exist before acting on them.
Sourcepub fn percent_decode(input: &str) -> String
pub fn percent_decode(input: &str) -> String
Decodes percent-encoded byte sequences (e.g. %20 -> ' ', %2F -> '/')
using standard library without external dependencies.
Lossy in the presence of non-UTF-8 bytes; prefer percent_decode_bytes on
unix where filenames may not be valid UTF-8.
Sourcepub fn percent_decode_bytes(input: &str) -> Vec<u8> ⓘ
pub fn percent_decode_bytes(input: &str) -> Vec<u8> ⓘ
Byte-exact percent decoder. Preserves arbitrary (non-UTF-8) path bytes.
Sourcepub fn unescape_shell_path(input: &str) -> String
pub fn unescape_shell_path(input: &str) -> String
Strips shell escape characters from file paths (e.g. \ -> ' ', \\ -> '\').