Skip to main content

validate_hub_version

Function validate_hub_version 

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

Rejects anything that is not a plain MAJOR.MINOR.PATCH numeric triplet, optionally followed by a -prerelease/+build suffix drawn from a safe character set. This exists for two reasons: to reject mutable refs like "main" or "latest" as a Hub version (a Hub version must be fixed and checksum-verifiable, never a moving target with no hash to verify against), and — just as importantly — to keep the whole string, suffix included, safe to use as a path component and a URL segment. ensure_cached_hub joins this value directly into a cache path (cache_root.join("warble").join("hub").join(version)) and interpolates it into a release URL; a suffix left unvalidated (as an earlier version of this function did, checking only the pre--/+ core) lets a value like "1.0.0-../../../ESCAPED" pass as a “valid triplet” while smuggling .. path segments through to Path::join, writing (and owner-only-chmod-ing) a directory outside the intended cache subtree — independent of whether the subsequent fetch ever succeeds. So every character of version, not just the numeric core, is checked here before any path or URL is built from it.