Skip to main content

FileSystemResolver

Struct FileSystemResolver 

Source
pub struct FileSystemResolver { /* private fields */ }
Expand description

Filesystem resolver with canonical root-containment checks, for TRUSTED hosts (a CLI, a static-site build). Not for untrusted input.

Every candidate is canonicalized (symlinks resolved) and only then checked against the canonical root. This is deliberately NOT a lexical ban on .., which is wrong on both sides: TOO STRICT (a document in chapters/ including ../shared/glossary.crv is a normal book layout whose canonical target is inside the root) and TOO WEAK (a symlink inside the root pointing out of it, or an absolute path, escapes with no .. present at all).

Implementations§

Source§

impl FileSystemResolver

Source

pub fn new(root: impl AsRef<Path>) -> Result<Self>

Canonicalizes root up front; fails if it does not exist, and refuses a spec that is not ABSOLUTE.

A relative spec names no root: every canonicalizer resolves one against the process working directory, the value §19 forbids the root defaulting to. The test has to be on the CONFIGURED value - the canonicalized result is always absolute. A front end keeps the convenience by absolutizing its own flag before constructing this.

Source

pub fn with_max_file_bytes(self, bytes: Option<u64>) -> Self

Largest target this resolver will read. None removes the cap.

Source

pub fn allow_absolute(self, allow: bool) -> Self

Allow absolute include paths. They are STILL subject to the same canonical containment check, so this only widens spelling, not reach.

Trait Implementations§

Source§

impl IncludeResolver for FileSystemResolver

Available on crate feature fs only.
Source§

fn unresolved_id( &self, include_path: &str, ctx: &IncludeContext<'_>, ) -> Option<String>

I11: a target that is simply not there is named by where it would be, the path a host watches. One that would land outside the root is refused like any other escape and keeps the directive’s spelling.

Source§

fn resolve( &self, include_path: &str, ctx: &IncludeContext<'_>, ) -> Result<IncludeResolved, IncludeDenial>

Resolve one directive path in its containing document context.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.