From 47e5f63ded5add806409bee1581cdb4aef54b509 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Thu, 22 Oct 2026 08:14:56 +0000 Subject: [PATCH] Keep file URL hosts that only start with "localhost" Found while testing crates/interchange/src/common.rs:68 Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/interchange/src/common.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/interchange/src/common.rs b/crates/interchange/src/common.rs index 2823ff755..9d4ed6b05 100644 --- a/crates/interchange/src/common.rs +++ b/crates/interchange/src/common.rs @@ -65,7 +65,9 @@ pub fn file_url_to_path(url: &str) -> String { return url.to_string(); } let rest = &url[7..]; - let rest = if rest.get(..9).is_some_and(|s| s.eq_ignore_ascii_case("localhost")) { &rest[9..] } else { rest }; + let is_localhost = + rest.get(..9).is_some_and(|s| s.eq_ignore_ascii_case("localhost")) && rest.get(9..).is_some_and(|after| after.is_empty() || after.starts_with('/')); + let rest = if is_localhost { &rest[9..] } else { rest }; let decoded = percent_decode(rest); // file:///C:/x -> C:/x if decoded.len() >= 3 && decoded.starts_with('/') && is_windows_abs(&decoded[1..]) { @@ -692,6 +694,14 @@ mod tests { } } + #[test] + fn file_url_localhost_prefix_host_is_kept() { + assert_eq!(file_url_to_path("file://localhost-nas/share/a.mov"), "//localhost-nas/share/a.mov"); + assert_eq!(file_url_to_path("file://LOCALHOSTX/a"), "//LOCALHOSTX/a"); + assert_eq!(file_url_to_path("file://localhost/a/b"), "/a/b"); + assert_eq!(file_url_to_path("file://LocalHost/a"), "/a"); + } + #[test] fn paths() { assert_eq!(resolve_path("media/a.mov", Some("/proj")), "/proj/media/a.mov");