pub struct PathResolver {
pub file_separator: char,
}Expand description
A PathResolver handles all operations for resolving, cleaning, and joining
paths. This struct includes operations for handling both web paths (request
URIs) and system paths.
The main emphasis of the struct is on creating clean and secure paths. Clean paths are void of duplicate parent and current directory references in the path name. Secure paths are paths which are restricted from accessing directories outside of a jail path, if specified.
Since joining two paths can result in an insecure path, this struct also handles the task of joining a parent (start) and child (target) path.
Like its counterpart in the Ruby Asciidoctor implementation, this struct makes no use of path utilities from the underlying Rust libraries. Instead, it handles all aspects of path manipulation. The main benefit of internalizing these operations is that the struct is able to handle both Posix and Windows paths independent of the operating system on which it runs. This makes the class both deterministic and easier to test.
Fields§
§file_separator: charFile separator to use for path operations. (Defaults to platform-appropriate separator.)
Implementations§
Source§impl PathResolver
impl PathResolver
Sourcepub fn posixify(&self, path: &str) -> String
pub fn posixify(&self, path: &str) -> String
Normalize path by converting any backslashes to forward slashes.
Sourcepub fn web_path(&self, target: &str, start: Option<&str>) -> String
pub fn web_path(&self, target: &str, start: Option<&str>) -> String
Resolve a web path from the target and start paths.
The main function of this operation is to resolve any parent references and remove any self references.
The target is assumed to be a path, not a qualified URI. That check should happen before this method is invoked.
Returns a path that joins the target path with the start path with any parent references resolved and self references removed.
Sourcepub fn is_web_root(&self, path: &str) -> bool
pub fn is_web_root(&self, path: &str) -> bool
Return true if the path is an absolute (root) web path (i.e. starts
with a '/'.
Trait Implementations§
Source§impl Clone for PathResolver
impl Clone for PathResolver
Source§fn clone(&self) -> PathResolver
fn clone(&self) -> PathResolver
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more