Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
arlosi marked this conversation as resolved.
Show resolved Hide resolved
}
SourceIdInner {
kind: SourceKind::LocalRegistry,
ref url,
Expand Down
49 changes: 49 additions & 0 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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""#,
);
}