tlc: Sprint 3 C2 — VFS parses file:// URLs as local

Previously parse() only recognised the local:// scheme. A
file:///path URL (the standard scheme used by browsers, text
editors, and many CLI tools) would be treated as an unknown
scheme and fall through to the 'unknown scheme → local'
fallback in for_path(), which works but is silent.

Now parse() explicitly handles file:// as an alias for local://,
making the VFS path normal form 'local://' after parsing.

Tests (1 new in vfs::path::tests):
  - parse_file_scheme_is_alias_for_local

Total: 1279 passing (was 1278; +1 new).
This commit is contained in:
kellito
2026-07-05 18:58:11 +03:00
parent d14d4ad72d
commit 08dbaf519a
@@ -150,6 +150,12 @@ impl VfsPath {
/// `cpio://`, `zip://`. Anything without a known scheme prefix is
/// treated as a local path (with `~`/env expansion).
pub fn parse(s: &str) -> Result<Self> {
// `file://` is the standard URL scheme for local files;
// accept it as an alias for `local://` (some tools pass
// file:// URLs from text editors, browsers, etc.).
if let Some(rest) = s.strip_prefix("file://") {
return Ok(Self::local(PathBuf::from(rest)));
}
if let Some(rest) = s.strip_prefix("local://") {
return Ok(Self::local(PathBuf::from(rest)));
}
@@ -420,6 +426,13 @@ mod tests {
assert_eq!(p.as_path(), Path::new("/etc"));
}
#[test]
fn parse_file_scheme_is_alias_for_local() {
let p = VfsPath::parse("file:///etc/passwd").unwrap();
assert_eq!(p.scheme(), "local");
assert_eq!(p.as_path(), Path::new("/etc/passwd"));
}
#[test]
fn parse_tilde_expands() {
let p = VfsPath::parse("~").unwrap();