mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25: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
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -4054,6 +4054,12 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urlencoding"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||
|
||||
[[package]]
|
||||
name = "usvg"
|
||||
version = "0.29.0"
|
||||
|
@ -4409,6 +4415,7 @@ dependencies = [
|
|||
"junction",
|
||||
"tempfile",
|
||||
"tracing",
|
||||
"urlencoding",
|
||||
"uv-warnings",
|
||||
]
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ tracing-tree = { version = "0.3.0" }
|
|||
unicode-width = { version = "0.1.11" }
|
||||
unscanny = { version = "0.1.0" }
|
||||
url = { version = "2.5.0" }
|
||||
urlencoding = { version = "2.1.3" }
|
||||
uuid = { version = "1.7.0", default-features = false }
|
||||
walkdir = { version = "2.4.0" }
|
||||
which = { version = "6.0.0" }
|
||||
|
|
|
@ -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