pub fn sanitize_stem(name: &str) -> StringExpand description
Reduces a network name to a single safe filename stem. The name comes from
input content, so an unsanitized value like ../../etc/x or /abs/x used
in out_dir.join(...) would write outside out_dir. Keeps ASCII
alphanumerics, -, _, and .; every other character (path separators
included) becomes _. Leading dots are stripped so the result is never
., .., or a hidden file; trailing dots are trimmed and Windows
reserved device names get a leading _, both invalid as Windows
filenames; the length is capped at 120 bytes; and an empty result
falls back to case.
A name the sanitizer had to change carries a hash of the original, so two
distinct names that would sanitize identically (a/b and a_b, say)
cannot silently overwrite each other’s files in a multi case export. A
name that already ends in the suffix shape is hashed too, so a case can
never be named to impersonate another case’s disambiguated stem: the
suffixed and unsuffixed name spaces stay disjoint. Any other safe name
passes through unchanged.