Avoid panic for invalid, non-base index URLs (#4527)

## Summary

See: https://github.com/astral-sh/uv/issues/4510
This commit is contained in:
Charlie Marsh 2024-06-25 14:32:58 -04:00 committed by GitHub
parent 904957bf80
commit a07e70d93a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View file

@ -137,6 +137,9 @@ pub enum ErrorKind {
#[error("Expected a file URL, but received: {0}")]
NonFileUrl(Url),
#[error("Expected an index URL, but received non-base URL: {0}")]
CannotBeABase(Url),
#[error(transparent)]
DistInfo(#[from] install_wheel_rs::Error),

View file

@ -270,7 +270,7 @@ impl RegistryClient {
// Format the URL for PyPI.
let mut url: Url = index.clone().into();
url.path_segments_mut()
.unwrap()
.map_err(|()| ErrorKind::CannotBeABase(index.clone().into()))?
.pop_if_empty()
.push(package_name.as_ref())
// The URL *must* end in a trailing slash for proper relative path behavior