Skip to content

Commit

Permalink
Avoid panic for invalid, non-base index URLs (#4527)
Browse files Browse the repository at this point in the history
## Summary

See: #4510
  • Loading branch information
charliermarsh committed Jun 25, 2024
1 parent 904957b commit a07e70d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions crates/uv-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a07e70d

Please sign in to comment.