Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions crates/uv-distribution-types/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
}

Expand Down
8 changes: 3 additions & 5 deletions crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UrlString, ToUrlError> {
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)
}

Expand Down Expand Up @@ -3995,9 +3994,8 @@ fn normalize_requirement(requirement: Requirement, root: &Path) -> Result<Requir
// Redact the credentials.
redact_credentials(&mut location);

// Remove the fragment and query from the URL; they're already present in the source.
// Remove the fragment from the URL; it's already present in the source.
location.set_fragment(None);
location.set_query(None);

// Reconstruct the PEP 508 URL from the underlying data.
let url = Url::from(ParsedArchiveUrl {
Expand Down