Skip to main content

contained_join

Function contained_join 

Source
pub fn contained_join(base: &Path, untrusted: &str) -> Result<PathBuf, FsError>
Expand description

Join an untrusted path to a base directory with traversal clamping.

Component-walk normalization:

  • Skips . components
  • Clamps .. at root (never goes above base)
  • Strips RootDir and Prefix components
  • Rejects NUL bytes in the raw &str (checked before Path conversion)

Use this for constructing paths where .. should be harmless (clamped). For I/O where traversal is never valid, use validate_relative_path instead.