Skip to main content

resolve_uri

Function resolve_uri 

Source
pub fn resolve_uri(system_id: &str, base: Option<&str>) -> String
Expand description

Resolve a SYSTEM literal to a filesystem path (joining against base_url’s parent directory for relative literals), read the file, and return its bytes. Used by external general-entity loading; mirrors the path-resolution rule in XmlBytesReader::load_external_subset.

http:// and https:// URIs are rejected — v0.1 doesn’t fetch over the network. file:// prefixes are stripped. Resolve a (possibly relative) SYSTEM identifier against a base URI into an absolute URL string.

The parser is the authority on base URI semantics — see XML 1.0 § 4.2.2 + errata E18. Doing the join here means every EntityResolver implementation can stay a simple “open-this-URL” function rather than re-implementing URI math.

Rules:

  • If system_id already has a URI scheme (contains "://") or is an absolute filesystem path (starts with /), it’s returned verbatim — already absolute.
  • If base is None, system_id is returned verbatim (best effort — the resolver will handle relative paths as it sees fit).
  • Otherwise the parent directory of base is joined with system_id (preserving any file:// scheme on base).

The result may still contain .. segments — they’re left for the resolver’s own canonicalisation step (e.g. FilesystemResolver::validate_path calls canonicalize, which resolves them and follows the security check on the result).