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

cargo install foo=1.2.3 does not detect invalid character #15318

Open
HKalbasi opened this issue Mar 16, 2025 · 3 comments
Open

cargo install foo=1.2.3 does not detect invalid character #15318

HKalbasi opened this issue Mar 16, 2025 · 3 comments
Labels
C-bug Category: bug Command-add Command-install S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@HKalbasi
Copy link
Member

HKalbasi commented Mar 16, 2025

Problem

The cargo add foo=1.2.3 says that = is not a valid character for a crate name, but cargo install foo=1.2.3 tries to download foo=1.2.3 crate. If it tries to detect the = and == and suggest using @ both in cargo add and cargo install, it would be even better.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version


@HKalbasi HKalbasi added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Mar 16, 2025
@epage epage added Command-install S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review Command-add and removed S-triage Status: This issue is waiting on initial triage. labels Mar 17, 2025
@epage
Copy link
Contributor

epage commented Mar 17, 2025

Good call on having the two commands match. I think the one benefit to the way cargo install does it is it will allow us to report a correct name if a typo was present which caused it to be invalid. Unsure which is more likely to happen but apparently you ran into this case, so maybe we go with that?

And good idea on checking if @ is missing and reporting that. Depending on the typo, there could be a couple of cases we could hit

  • <name><op><version>, like your foo=1.2.3. This could also be ^ or several others. The way to handle this is to check for the first invalid character and split the string on it and see if it parses if a @ is inserted at that point
  • <name><version>, like foo1.2.3. This becomes more difficult to catch because there can be numbers in package names but not .. Maybe i we find an invalid character, we backtrack for any digits?

@nooma-42
Copy link
Contributor

Could there also be a crate with multiple invalid characters like foo>=1.2.3 or foo^=1.2.3 or foo:1.2.3? where checking multiple characters is required before replacing with@.

@epage
Copy link
Contributor

epage commented Mar 20, 2025

: is actually an alternative character to @ and is what was used before cargo add was added.

For the rest of those cases, that is covered by my suggestion to insert @ between the last valid character and the first invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-add Command-install S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

No branches or pull requests

3 participants