From a07e70d93a532a279a22042c9a915e20df2b9618 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 25 Jun 2024 14:32:58 -0400 Subject: [PATCH] Avoid panic for invalid, non-base index URLs (#4527) ## Summary See: https://github.com/astral-sh/uv/issues/4510 --- crates/uv-client/src/error.rs | 3 +++ crates/uv-client/src/registry_client.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/uv-client/src/error.rs b/crates/uv-client/src/error.rs index 6d2c2baeac88..c873e6a6ac34 100644 --- a/crates/uv-client/src/error.rs +++ b/crates/uv-client/src/error.rs @@ -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), diff --git a/crates/uv-client/src/registry_client.rs b/crates/uv-client/src/registry_client.rs index b758994e96df..acd003931915 100644 --- a/crates/uv-client/src/registry_client.rs +++ b/crates/uv-client/src/registry_client.rs @@ -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