mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-02 04:48:18 +00:00
Avoid stripping query parameters from URLs (#10253)
## Summary Closes https://github.com/astral-sh/uv/issues/10251.
This commit is contained in:
parent
c77aa5820b
commit
cf88828e55
2 changed files with 14 additions and 9 deletions
|
|
@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue