diff --git a/crates/uv-distribution-types/src/file.rs b/crates/uv-distribution-types/src/file.rs index bfbbbf7e4..5336a1b7f 100644 --- a/crates/uv-distribution-types/src/file.rs +++ b/crates/uv-distribution-types/src/file.rs @@ -157,15 +157,22 @@ impl UrlString { /// Return the [`UrlString`] with any query parameters and fragments removed. pub fn base_str(&self) -> &str { self.as_ref() - .split_once(['#', '?']) + .split_once('?') + .or_else(|| self.as_ref().split_once('#')) .map(|(path, _)| path) .unwrap_or(self.as_ref()) } - /// Return the [`UrlString`] with any query parameters and fragments removed. + /// Return the [`UrlString`] with any fragments removed. #[must_use] - pub fn as_base_url(&self) -> Self { - Self(self.base_str().to_string()) + pub fn without_fragment(&self) -> Self { + Self( + self.as_ref() + .split_once('#') + .map(|(path, _)| path) + .unwrap_or(self.as_ref()) + .to_string(), + ) } } diff --git a/crates/uv-resolver/src/lock/mod.rs b/crates/uv-resolver/src/lock/mod.rs index 2e523458e..7d85bcd6c 100644 --- a/crates/uv-resolver/src/lock/mod.rs +++ b/crates/uv-resolver/src/lock/mod.rs @@ -3862,15 +3862,14 @@ impl<'de> serde::Deserialize<'de> for Hash { /// Convert a [`FileLocation`] into a normalized [`UrlString`]. fn normalize_file_location(location: &FileLocation) -> Result { match location { - FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.as_base_url()), + FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.without_fragment()), FileLocation::RelativeUrl(_, _) => Ok(normalize_url(location.to_url()?)), } } -/// Convert a [`Url`] into a normalized [`UrlString`]. +/// Convert a [`Url`] into a normalized [`UrlString`] by removing the fragment. fn normalize_url(mut url: Url) -> UrlString { url.set_fragment(None); - url.set_query(None); UrlString::from(url) } @@ -3995,9 +3994,8 @@ fn normalize_requirement(requirement: Requirement, root: &Path) -> Result