mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Apply percent-decoding to file-based URLs (#1541)
## Summary Closes https://github.com/astral-sh/uv/issues/1537.
This commit is contained in:
parent
a97c207674
commit
01ffc36520
4 changed files with 27 additions and 2 deletions
|
@ -21,6 +21,7 @@ fs2 = { workspace = true }
|
|||
junction = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
urlencoding = { workspace = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
@ -31,14 +31,18 @@ impl<T: AsRef<Path>> Normalized for T {
|
|||
///
|
||||
/// On other platforms, this is a no-op.
|
||||
pub fn normalize_url_path(path: &str) -> Cow<'_, str> {
|
||||
// Apply percent-decoding to the URL.
|
||||
let path = urlencoding::decode(path).unwrap_or(Cow::Borrowed(path));
|
||||
|
||||
// Return the path.
|
||||
if cfg!(windows) {
|
||||
Cow::Owned(
|
||||
path.strip_prefix('/')
|
||||
.unwrap_or(path)
|
||||
.unwrap_or(&path)
|
||||
.replace('/', std::path::MAIN_SEPARATOR_STR),
|
||||
)
|
||||
} else {
|
||||
Cow::Borrowed(path)
|
||||
path
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,5 +75,17 @@ mod tests {
|
|||
"./ferris/wheel-0.42.0.tar.gz"
|
||||
);
|
||||
}
|
||||
|
||||
if cfg!(windows) {
|
||||
assert_eq!(
|
||||
normalize_url_path("./wheel%20cache/wheel-0.42.0.tar.gz"),
|
||||
".\\wheel cache\\wheel-0.42.0.tar.gz"
|
||||
);
|
||||
} else {
|
||||
assert_eq!(
|
||||
normalize_url_path("./wheel%20cache/wheel-0.42.0.tar.gz"),
|
||||
"./wheel cache/wheel-0.42.0.tar.gz"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue