Skip to main content

resolve_doc_path

Function resolve_doc_path 

Source
pub fn resolve_doc_path(
    docs_dir: &Path,
    rel: &str,
) -> Result<PathBuf, PathGuardError>
Expand description

Resolve a client-supplied doc-relative path (e.g. "guide/intro.md") to a canonical absolute path strictly inside docs_dir, or reject. docs_dir MUST already be canonicalized by the caller. Layered checks mirror the original validateRepoDocPath:

  1. backslash -> Traversal; absolute / leading / -> Absolute.
  2. strip leading ./; any .. component -> Traversal; empty -> Traversal.
  3. require a .md suffix -> else NotMarkdown.
  4. lexical: docs_dir.join(rel) must stay under docs_dir.
  5. canonicalize(): missing -> NotFound; realpath escaping docs_dir (symlink escape) -> Traversal.
  6. the canonical target must be a regular file -> else NotAFile.