-
Notifications
You must be signed in to change notification settings - Fork 620
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
Use the same feature and dep name validation rules from Cargo #7379
Conversation
Allowing I'm wondering though whether we should migrate to the ruleset that cargo is using (see https://doc.rust-lang.org/cargo/reference/features.html#the-features-section):
The original issue is complaining about the server having different rules than cargo, and while allowing |
Sounds make sense. I will fix it tomorrow. |
Might be worth getting opinions from the rest of the team first. I'm not sure if there is a reason why crates.io is currently more restrictive than cargo, but some of the other team members might know. |
I'm not aware of any intentional restrictions put in place here. Looking through the history outlined here, it looks like this originally shared an implementation with the crate name validation logic and that we've just incrementally allowed more characters as they were requested. As I understand it, we're only easing the constraints on the
In that case I don't see any issues with lifting these constraints on feature names to align with cargo. I am a bit confused by some of our existing logic though:
Not that it would need to be done in this PR, but it seems like maybe we should be more strict when validating the assert!(Crate::valid_feature("0"));
assert!(Crate::valid_feature("-"));
assert!(Crate::valid_feature("0/bar"));
assert!(Crate::valid_feature("-/bar")); It's also not clear to me if we should allow the following always, or possibly verify that a dependency has been reanamed to assert!(Crate::valid_feature("_"));
assert!(Crate::valid_feature("_/bar")); |
From the Cargo side:
For future name: https://github.com/rust-lang/cargo/blob/b1a3ad24c4088d125fd478670a2e171c3951cfa6/src/cargo/core/summary.rs#L433
|
This comment was marked as outdated.
This comment was marked as outdated.
We discussed it in tonight's meeting:
|
Signed-off-by: hi-rustin <[email protected]>
Signed-off-by: hi-rustin <[email protected]>
Signed-off-by: hi-rustin <[email protected]>
9cda4d0
to
318e165
Compare
This comment was marked as outdated.
This comment was marked as outdated.
7d91969
to
8753f8a
Compare
Signed-off-by: hi-rustin <[email protected]>
Signed-off-by: hi-rustin <[email protected]>
AppResult. Signed-off-by: hi-rustin <[email protected]>
Signed-off-by: hi-rustin <[email protected]>
8753f8a
to
b23fe07
Compare
.
in the feature name
src/models/krate.rs
Outdated
pub fn valid_name(name: &str) -> AppResult<()> { | ||
if name.chars().count() > MAX_NAME_LENGTH { | ||
return Err(cargo_err(&format!( | ||
"the name `{}` is too long (max {} characters)", | ||
name, MAX_NAME_LENGTH | ||
))); | ||
} | ||
Crate::valid_ident(name, "crate name") | ||
} | ||
|
||
fn valid_ident(name: &str) -> bool { | ||
Self::valid_feature_prefix(name) | ||
&& name | ||
.chars() | ||
.next() | ||
.map(char::is_alphabetic) | ||
.unwrap_or(false) | ||
pub fn valid_dependency_name(name: &str) -> AppResult<()> { | ||
if name.chars().count() > MAX_NAME_LENGTH { | ||
return Err(cargo_err(&format!( | ||
"the name `{}` is too long (max {} characters)", | ||
name, MAX_NAME_LENGTH | ||
))); | ||
} | ||
Crate::valid_ident(name, "dependency name") | ||
} | ||
|
||
pub fn valid_dependency_name(name: &str) -> bool { | ||
let under_max_length = name.chars().take(MAX_NAME_LENGTH + 1).count() <= MAX_NAME_LENGTH; | ||
Crate::valid_dependency_ident(name) && under_max_length | ||
} | ||
// Checks that the name is a valid identifier. | ||
// 1. The name must be non-empty. | ||
// 2. The first character must be an ASCII character or `_`. | ||
// 3. The remaining characters must be ASCII alphanumerics or `-` or `_`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand why you changed all of these implementations too? I thought the goal of this PR was to adjust the validation rules for feature names, but not for crate names 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember the last meeting, we decided not to allow unicode for crate names, but we can follow the same rules for the validations.
But if you think we should only change the feature name first. I can revert my changes for crate names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't change the create name validation as well, _a?/feature_name
still is invalid in crates.io but it works in Cargo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changing the rules on crate names should be out of scope for this PR. That would need a bit more investigation since these are relevant for URLs, S3 paths, and other things where allowing additional characters could have unintended consequences. Let's focus this PR on just the feature names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. I will revert it. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted it in f47425f
I retained the modification of the message as it provides a clearer error message to users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I retained the modification of the message as it provides a clearer error message to users.
the problem is that this makes the diff a lot harder to review because the PR is doing multiple things at once. (see https://mtlynch.io/code-review-love/#5-narrowly-scope-changes 😉)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem is that this makes the diff a lot harder to review because the PR is doing multiple things at once.
Sorry for the big PR. I tried to make sure one commit only had one main change. Could you please review it by commit? The reason it has a really big change is the old validations for create name and dep name also use some feature validation rules(functions). We mixed them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think it is still really difficult to review. I can split it into three different PRs. Sorry again for the confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one: #7500
Signed-off-by: hi-rustin <[email protected]>
c495ff4
to
f47425f
Compare
close #7250
.
in the feature name. I added some unit tests and integration tests for it.The summary:
2. can only start with most letters or
_
3. can only contain numbers,
-
,_
, or most letters.2. can only contain numbers, letters,
-
,_
2. can only contain numbers, letters,
-
,_
(Nothing changes)2. can only start with most letters or
_
3. can only contain numbers,
-
,_
, or most letters._
2. can only contain numbers, letters,
-
,_
2. can only start with ASCII letters or
_
3. can only contain numbers,
-
,_
, or ASCII letters. (Nothing changes)_
, or0
to9
2. can only contain numbers,
+
,-
,_
,.
, or most letters+
,-
,_
, or most letters_
, or0
to9
2. can only contain numbers,
+
,-
,_
,.
, or most letters+
,-
,_
, or most letters1. so the first part is the same as the dep name
2. the second part is the same as the normal feature name.
+
,-
,_
, or most letters1. so the first part is the same as the dep name
2. the second part is the same as the normal feature name.