Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

fix: do now allow empty spec name #63

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions src/bin/cargo-info/command/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
.map(String::as_str)
.unwrap();
let spec = PackageIdSpec::parse(package)?;
if spec.name().is_empty() {
return Err(CliError::new(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from cargo. So I guess it is the correct way to bail out an error with the error code.

anyhow::format_err!("package ID specification must have a name"),
101,
));
}

let reg_or_index = args.registry_or_index(config)?;
ops::info(&spec, config, reg_or_index)?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_information/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod basic;
mod features;
mod help;
mod not_found;
mod specify_empty_version_with_url;
mod specify_version_outside_ws;
mod specify_version_with_url_but_registry_is_not_matched;
mod specify_version_with_ws_and_match_multiple_versions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use cargo_test_macro::cargo_test;
use cargo_test_support::{curr_dir, registry::RegistryBuilder};

use super::cargo_info;

#[cargo_test]
fn case() {
let _ = RegistryBuilder::new()
.alternative()
.no_configure_token()
.build();
cargo_test_support::registry::Package::new("my-package", "99999.0.0-alpha.1+my-package")
.alternative(true)
.publish();

cargo_info()
.arg("https://crates.io")
.arg("--registry=alternative")
.assert()
.failure()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error: package ID specification must have a name