Expand description
Path sanitization utilities.
Provides sanitize_for_fs() which transforms an arbitrary string into a
filesystem-safe identifier using a djb2 hash and radix-36 encoding. Used
for session directories, worktree slugs, and any other case where an
untrusted string must become a safe directory or file name.
Constants§
- MAX_
LINK_ HOPS - How many symbolic links a resolution follows before it takes a loop for
one, as the OS does (
SYMLOOP_MAX). - MAX_
SANITIZED_ LENGTH - Public constant for external crates (e.g. agix-history tests) that need to verify sanitized output length bounds.
Functions§
- first_
below - When
reststarts with a name: that name under the resolvedout— a link the OS could not resolve, if it is one — and the rest after it. - normalize_
lexically pwith.dropped and each..taking off the component before it, without touching the filesystem, so it does not know a..after a symlink climbs out of the link’s target (resolve_physicallydoes).- put_
back restput onto the resolvedoutlexically.- resolve_
physically - Where
pathlands on this machine’s disk: its deepest prefix that exists, resolved by the OS, with the rest put back on lexically. The rest does not exist, so it holds no symlink a lexical..could misjudge — except its first name, a link the OS cannot resolve because what it points at does not exist yet, which a write follows and so is followed here. - sanitize_
for_ fs - Sanitize a string for use as a filesystem component (file name or directory).