Discard fragments when parsing unnamed URLs (#3940)

## Summary

Closes https://github.com/astral-sh/uv/issues/3934.
This commit is contained in:
Charlie Marsh 2024-05-31 09:54:15 -04:00 committed by GitHub
parent 72b1642232
commit 8c11f99fdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 67 additions and 6 deletions

View file

@ -155,6 +155,13 @@ impl VerbatimUrl {
pub fn to_url(&self) -> Url {
self.url.clone()
}
/// Return the underlying [`Path`], if the URL is a file URL.
pub fn as_path(&self) -> Result<PathBuf, VerbatimUrlError> {
self.url
.to_file_path()
.map_err(|_| VerbatimUrlError::UrlConversion(self.url.to_file_path().unwrap()))
}
}
// This impl is written out because the `derive` doesn't seem to get it right.