fix: sparse URLs in TomlLockfileSourceId

This commit is contained in:
Vito Secona 2025-09-20 15:07:44 +07:00
parent d93be027f1
commit 00085c1aa7

View File

@ -109,9 +109,13 @@ impl TomlLockfileSourceId {
EncodableSourceIdError(EncodableSourceIdErrorKind::InvalidSource(source.clone()).into())
})?;
let url = Url::parse(url).map_err(|msg| EncodableSourceIdErrorKind::InvalidUrl {
url: url.to_string(),
msg: msg.to_string(),
// Sparse URLs store the kind prefix (sparse+) in the URL. Therefore, for sparse kinds, we
// want to use the raw `source` instead of the splitted `url`.
let url = Url::parse(if kind == "sparse" { &source } else { url }).map_err(|msg| {
EncodableSourceIdErrorKind::InvalidUrl {
url: url.to_string(),
msg: msg.to_string(),
}
})?;
let kind = match kind {
@ -347,7 +351,7 @@ mod tests {
ok(
"sparse+https://my-crates.io",
SourceKind::SparseRegistry,
"https://my-crates.io/",
"sparse+https://my-crates.io",
);
ok(
"registry+https://github.com/rust-lang/crates.io-index",