Avoid panics for cannot-be-a-base URLs (#13406)

Following #13376, avoid `.unwrap()` on `Url::path_segments()`.

I also added some unwrap-safety comments.
This commit is contained in:
konsti
2025-05-13 04:29:26 +02:00
committed by GitHub
parent 6df588bb00
commit 3b125dbe71
2 changed files with 7 additions and 2 deletions
+4 -2
View File
@@ -66,6 +66,8 @@ pub enum Error {
},
#[error("Invalid download URL")]
InvalidUrl(#[from] url::ParseError),
#[error("Invalid download URL: {0}")]
InvalidUrlFormat(Url),
#[error("Invalid path in file URL: `{0}`")]
InvalidFileUrl(String),
#[error("Failed to create download directory")]
@@ -643,9 +645,9 @@ impl ManagedPythonDownload {
// decodes to.
let filename = url
.path_segments()
.unwrap()
.ok_or_else(|| Error::InvalidUrlFormat(url.clone()))?
.next_back()
.unwrap()
.ok_or_else(|| Error::InvalidUrlFormat(url.clone()))?
.replace("%2B", "-");
debug_assert!(
filename