mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-26 12:09:12 +00:00
Avoid panicking on cannot-be-a-base URLs (#2461)
`path_segments_mut` returns an `Err` for cannot-be-a-base URLs. These won't be valid when we try to fetch them anyway, but we need to avoid a panic. Closes https://github.com/astral-sh/uv/issues/2460.
This commit is contained in:
parent
b50cb3e79e
commit
2fb8df3769
1 changed files with 11 additions and 0 deletions
|
@ -21,6 +21,11 @@ impl CanonicalUrl {
|
||||||
pub fn new(url: &Url) -> Self {
|
pub fn new(url: &Url) -> Self {
|
||||||
let mut url = url.clone();
|
let mut url = url.clone();
|
||||||
|
|
||||||
|
// If the URL cannot be a base, then it's not a valid URL anyway.
|
||||||
|
if url.cannot_be_a_base() {
|
||||||
|
return Self(url);
|
||||||
|
}
|
||||||
|
|
||||||
// Strip a trailing slash.
|
// Strip a trailing slash.
|
||||||
if url.path().ends_with('/') {
|
if url.path().ends_with('/') {
|
||||||
url.path_segments_mut().unwrap().pop_if_empty();
|
url.path_segments_mut().unwrap().pop_if_empty();
|
||||||
|
@ -194,6 +199,12 @@ mod tests {
|
||||||
)?,
|
)?,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Two URLs that cannot be a base should be considered equal.
|
||||||
|
assert_eq!(
|
||||||
|
CanonicalUrl::parse("git+https:://github.com/pypa/sample-namespace-packages.git")?,
|
||||||
|
CanonicalUrl::parse("git+https:://github.com/pypa/sample-namespace-packages.git")?,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue