|
@@ -2508,6 +2508,7 @@ fn path_to_file_url_segments_windows(
|
|
|
}
|
|
}
|
|
|
let mut components = path.components();
|
|
let mut components = path.components();
|
|
|
|
|
|
|
|
|
|
+ let host_start = serialization.len() + 1;
|
|
|
let host_end;
|
|
let host_end;
|
|
|
let host_internal;
|
|
let host_internal;
|
|
|
match components.next() {
|
|
match components.next() {
|
|
@@ -2534,15 +2535,24 @@ fn path_to_file_url_segments_windows(
|
|
|
_ => return Err(()),
|
|
_ => return Err(()),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ let mut path_only_has_prefix = true;
|
|
|
for component in components {
|
|
for component in components {
|
|
|
if component == Component::RootDir {
|
|
if component == Component::RootDir {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ path_only_has_prefix = false;
|
|
|
// FIXME: somehow work with non-unicode?
|
|
// FIXME: somehow work with non-unicode?
|
|
|
let component = component.as_os_str().to_str().ok_or(())?;
|
|
let component = component.as_os_str().to_str().ok_or(())?;
|
|
|
serialization.push('/');
|
|
serialization.push('/');
|
|
|
serialization.extend(percent_encode(component.as_bytes(), PATH_SEGMENT));
|
|
serialization.extend(percent_encode(component.as_bytes(), PATH_SEGMENT));
|
|
|
}
|
|
}
|
|
|
|
|
+ // A windows drive letter must end with a slash.
|
|
|
|
|
+ if serialization.len() > host_start
|
|
|
|
|
+ && parser::is_windows_drive_letter(&serialization[host_start..])
|
|
|
|
|
+ && path_only_has_prefix
|
|
|
|
|
+ {
|
|
|
|
|
+ serialization.push('/');
|
|
|
|
|
+ }
|
|
|
Ok((host_end, host_internal))
|
|
Ok((host_end, host_internal))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2567,6 +2577,14 @@ fn file_url_segments_to_pathbuf(
|
|
|
bytes.push(b'/');
|
|
bytes.push(b'/');
|
|
|
bytes.extend(percent_decode(segment.as_bytes()));
|
|
bytes.extend(percent_decode(segment.as_bytes()));
|
|
|
}
|
|
}
|
|
|
|
|
+ // A windows drive letter must end with a slash.
|
|
|
|
|
+ if bytes.len() > 2 {
|
|
|
|
|
+ if matches!(bytes[bytes.len() -2], b'a'..=b'z' | b'A'..=b'Z')
|
|
|
|
|
+ && matches!(bytes[bytes.len() - 1], b':' | b'|')
|
|
|
|
|
+ {
|
|
|
|
|
+ bytes.push(b'/');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
let os_str = OsStr::from_bytes(&bytes);
|
|
let os_str = OsStr::from_bytes(&bytes);
|
|
|
let path = PathBuf::from(os_str);
|
|
let path = PathBuf::from(os_str);
|
|
|
debug_assert!(
|
|
debug_assert!(
|