Skip to main content

escapes_root

Function escapes_root 

Source
pub fn escapes_root(path: impl AsRef<Path>) -> bool
Expand description

Whether path, resolved against a root, would land outside it.

Two ways a root-relative path can escape the tree it is joined onto: an absolute path (or a Windows drive prefix), which root.join(path) jumps to wholesale, ignoring the root entirely; and one whose normalized form still leads with .., a climb above the root that the parent/.. folding could not cancel.

ChangeSet::apply refuses either before it writes or journals anything, so a set assembled from untrusted input — a link target authored by whoever wrote the document, a path out of a config file — can never name a file outside the tree it was pointed at.

A path that stays within the root (notes/a.md, or ../sibling/b.md where the leading climb is cancelled by what precedes it) returns false.