Skip to content

Commit 00085c1

Browse files
committed
fix: sparse URLs in TomlLockfileSourceId
1 parent d93be02 commit 00085c1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/cargo-util-schemas/src/lockfile.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ impl TomlLockfileSourceId {
109109
EncodableSourceIdError(EncodableSourceIdErrorKind::InvalidSource(source.clone()).into())
110110
})?;
111111

112-
let url = Url::parse(url).map_err(|msg| EncodableSourceIdErrorKind::InvalidUrl {
113-
url: url.to_string(),
114-
msg: msg.to_string(),
112+
// Sparse URLs store the kind prefix (sparse+) in the URL. Therefore, for sparse kinds, we
113+
// want to use the raw `source` instead of the splitted `url`.
114+
let url = Url::parse(if kind == "sparse" { &source } else { url }).map_err(|msg| {
115+
EncodableSourceIdErrorKind::InvalidUrl {
116+
url: url.to_string(),
117+
msg: msg.to_string(),
118+
}
115119
})?;
116120

117121
let kind = match kind {
@@ -347,7 +351,7 @@ mod tests {
347351
ok(
348352
"sparse+https://my-crates.io",
349353
SourceKind::SparseRegistry,
350-
"https://my-crates.io/",
354+
"sparse+https://my-crates.io",
351355
);
352356
ok(
353357
"registry+https://github.com/rust-lang/crates.io-index",

0 commit comments

Comments
 (0)