Windows: implement conversion to/from UNC paths
@@ -414,3 +414,21 @@ fn test_origin_hash() {
assert_ne!(hash(&opaque_origin), hash(&same_opaque_origin));
assert_ne!(hash(&opaque_origin), hash(&other_opaque_origin));
}
+
+#[cfg(windows)]
+#[test]
+fn test_windows_unc_path() {
+ let url = Url::from_file_path(Path::new(r"\\host\share\path\file.txt")).unwrap();
+ assert_eq!(url.as_str(), "file://host/share/path/file.txt");
+
+ let path = url.to_file_path().unwrap();
+ assert_eq!(path.to_str(), Some(r"\\host\share\path\file.txt"));
+
+ // Another way to write these:
+ let url = Url::from_file_path(Path::new(r"\\?\UNC\host\share\path\file.txt")).unwrap();
+ assert_eq!(url.as_str(), "file://host/share/path/file.txt");
+
+ // Paths starting with "\\.\" (Local Device Paths) are intentionally not supported.
+ let url = Url::from_file_path(Path::new(r"\\.\some\path\file.txt"));
+ assert!(url.is_err());
+}
\ No newline at end of file
