Skip to content

Commit 805c6fb

Browse files
committed
Fix erroneous searches with cargo install and out of bounds indexing
1 parent 4b808eb commit 805c6fb

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
167167
.into());
168168
}
169169
}
170+
171+
if crate_name != "."
172+
&& let Err(e) = package_name
173+
{
174+
return Err(anyhow::format_err!("{e}").into());
175+
}
170176
}
171177

172178
let mut from_cwd = false;

tests/testsuite/install.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,10 +3076,7 @@ fn emoji_name() {
30763076
.with_status(101)
30773077
.with_stdout_data("")
30783078
.with_stderr_data(str![[r#"
3079-
3080-
thread 'main' (939065) panicked at crates/cargo-util/src/registry.rs:24:44:
3081-
byte index 2 is not a char boundary; it is inside '🦀' (bytes 0..4) of `🦀`
3082-
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3079+
[ERROR] invalid character `🦀` in package name: `🦀`, the first character must be a Unicode XID start character (most letters or `_`)
30833080
30843081
"#]])
30853082
.run();
@@ -3092,8 +3089,7 @@ fn starts_with_number_case() {
30923089
.with_status(101)
30933090
.with_stdout_data("")
30943091
.with_stderr_data(str![[r#"
3095-
[UPDATING] `dummy-registry` index
3096-
[ERROR] could not find `23898932983` in registry `crates-io` with version `*`
3092+
[ERROR] invalid character `2` in package name: `23898932983`, the name cannot start with a digit
30973093
30983094
"#]])
30993095
.run();
@@ -3106,10 +3102,7 @@ fn mistaken_flag_case() {
31063102
.with_status(101)
31073103
.with_stdout_data("")
31083104
.with_stderr_data(str![[r#"
3109-
3110-
thread 'main' (939643) panicked at crates/cargo-util/src/registry.rs:24:44:
3111-
byte index 2 is not a char boundary; it is inside '–' (bytes 0..3) of `––path`
3112-
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3105+
[ERROR] invalid character `–` in package name: `––path`, the first character must be a Unicode XID start character (most letters or `_`)
31133106
31143107
"#]])
31153108
.run();

0 commit comments

Comments
 (0)