Skip to content

Commit 1913e70

Browse files
committed
Avoid stripping query parameters from URLs
1 parent c77aa58 commit 1913e70

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

crates/uv-distribution-types/src/file.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,22 @@ impl UrlString {
157157
/// Return the [`UrlString`] with any query parameters and fragments removed.
158158
pub fn base_str(&self) -> &str {
159159
self.as_ref()
160-
.split_once(['#', '?'])
160+
.split_once('?')
161+
.or_else(|| self.as_ref().split_once('#'))
161162
.map(|(path, _)| path)
162163
.unwrap_or(self.as_ref())
163164
}
164165

165-
/// Return the [`UrlString`] with any query parameters and fragments removed.
166+
/// Return the [`UrlString`] with any fragments removed.
166167
#[must_use]
167-
pub fn as_base_url(&self) -> Self {
168-
Self(self.base_str().to_string())
168+
pub fn without_fragment(&self) -> Self {
169+
Self(
170+
self.as_ref()
171+
.split_once('#')
172+
.map(|(path, _)| path)
173+
.unwrap_or(self.as_ref())
174+
.to_string(),
175+
)
169176
}
170177
}
171178

crates/uv-resolver/src/lock/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,15 +3862,14 @@ impl<'de> serde::Deserialize<'de> for Hash {
38623862
/// Convert a [`FileLocation`] into a normalized [`UrlString`].
38633863
fn normalize_file_location(location: &FileLocation) -> Result<UrlString, ToUrlError> {
38643864
match location {
3865-
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.as_base_url()),
3865+
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.without_fragment()),
38663866
FileLocation::RelativeUrl(_, _) => Ok(normalize_url(location.to_url()?)),
38673867
}
38683868
}
38693869

3870-
/// Convert a [`Url`] into a normalized [`UrlString`].
3870+
/// Convert a [`Url`] into a normalized [`UrlString`] by removing the fragment.
38713871
fn normalize_url(mut url: Url) -> UrlString {
38723872
url.set_fragment(None);
3873-
url.set_query(None);
38743873
UrlString::from(url)
38753874
}
38763875

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

3998-
// Remove the fragment and query from the URL; they're already present in the source.
3997+
// Remove the fragment from the URL; it's already present in the source.
39993998
location.set_fragment(None);
4000-
location.set_query(None);
40013999

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

0 commit comments

Comments
 (0)