Skip to main content

sanitize_relative_path

Function sanitize_relative_path 

pub fn sanitize_relative_path(
    path: impl AsRef<Path>,
) -> Result<PathBuf, UnsafePathError>
Expand description

Like sanitize_path but additionally requires the path to be relative, rejecting absolute paths and drive/UNC prefixes (UnsafePathError::Absolute).

Returns the cleaned relative path with . components dropped; join it onto a trusted root directory to confine filesystem access to within that root. This is the lexical primitive shared by safe filesystem mapping of untrusted relative paths (e.g. a static file server).