Fix sparse registry lockfile urls containing 'registry+sparse+'

This commit is contained in:
Arlo Siemsen 2022-09-09 22:30:34 -05:00
parent 0b84a35c2c
commit 931d8cbf99
2 changed files with 56 additions and 1 deletions

View File

@ -680,7 +680,13 @@ impl<'a> fmt::Display for SourceIdAsUrl<'a> {
kind: SourceKind::Registry,
ref url,
..
} => write!(f, "registry+{}", url),
} => {
if url.scheme().starts_with("sparse+") {
write!(f, "{}", url)
} else {
write!(f, "registry+{}", url)
}
}
SourceIdInner {
kind: SourceKind::LocalRegistry,
ref url,

View File

@ -1,6 +1,7 @@
//! Tests for alternative registries.
use cargo::util::IntoUrl;
use cargo_test_support::compare::assert_match_exact;
use cargo_test_support::publish::validate_alt_upload;
use cargo_test_support::registry::{self, Package, RegistryBuilder};
use cargo_test_support::{basic_manifest, git, paths, project};
@ -1309,3 +1310,51 @@ fn both_index_and_registry() {
.run();
}
}
#[cargo_test]
fn sparse_lockfile() {
let _registry = registry::RegistryBuilder::new()
.http_index()
.alternative()
.build();
Package::new("foo", "0.1.0").alternative(true).publish();
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "a"
version = "0.5.0"
authors = []
[dependencies]
foo = { registry = 'alternative', version = '0.1.0'}
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("-Zsparse-registry generate-lockfile")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.run();
assert_match_exact(
&p.read_lockfile(),
r#"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "a"
version = "0.5.0"
dependencies = [
"foo",
]
[[package]]
name = "foo"
version = "0.1.0"
source = "sparse+http://[..]/"
checksum = "f6a200a9339fef960979d94d5c99cbbfd899b6f5a396a55d9775089119050203""#,
);
}