Skip to main content

normalize_asset_path

Function normalize_asset_path 

Source
pub fn normalize_asset_path(raw: &str) -> Result<String, String>
Expand description

Normalize a declared asset path to a CANONICAL store-relative forward-slash string, rejecting absolute paths and any .. / root component. This is the lexical guard; crate::store::ensure_path_within_store is the resolved-path guard applied before any disk read.

The result is the record key, so it MUST be canonical: ./sources/x.pdf, sources/x.pdf, and sources/./x.pdf all denote the same file and must fold to the same key sources/x.pdf. The path is rebuilt from Normal components only (dropping CurDir); hostile ../root/prefix components are still hard errors (never silently sanitized), so a leading ./ is normalized away while a traversal attempt is rejected.