-
Notifications
You must be signed in to change notification settings - Fork 121
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
no periods in new contract names #192
no periods in new contract names #192
Conversation
src/cmd/new.rs
Outdated
@@ -27,6 +27,10 @@ pub(crate) fn execute<P>(name: &str, dir: Option<P>) -> Result<Option<String>> | |||
where | |||
P: AsRef<Path>, | |||
{ | |||
if name.contains('.') { |
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.
Rather than checking for individual invalid characters, we should rather only allow valid characters e.g. alphanumeric, underscores.
@ascjones good call, made that change and removed these invalid character checks. |
src/cmd/new.rs
Outdated
@@ -27,8 +27,8 @@ pub(crate) fn execute<P>(name: &str, dir: Option<P>) -> Result<Option<String>> | |||
where | |||
P: AsRef<Path>, | |||
{ | |||
if name.contains('-') { | |||
anyhow::bail!("Contract names cannot contain hyphens"); | |||
if !name.replace('_', "").chars().all(char::is_alphanumeric) { |
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 !name.replace('_', "").chars().all(char::is_alphanumeric) { | |
if !name.chars().all(|c| c.is_alphanumeric() || c == '_') { |
I think something like this is more readable (note I haven't checked whether that compiles or not)
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.
Good idea, probably a tad more efficient too. Made the change and it does indeed compile
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.
LGTM. @Robbepop can you just confirm the name validation is correct here - we should only allow alphanumeric or underscore?
@@ -27,8 +27,8 @@ pub(crate) fn execute<P>(name: &str, dir: Option<P>) -> Result<Option<String>> | |||
where | |||
P: AsRef<Path>, | |||
{ | |||
if name.contains('-') { | |||
anyhow::bail!("Contract names cannot contain hyphens"); | |||
if !name.chars().all(|c| c.is_alphanumeric() || c == '_') { |
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.
this allows _
as identifier which is invalid. however, I think this isn't too bad?
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.
Well spotted. Is that even a valid crate name?
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 just checked and cargo
does not immediately put a stop to having _
as crate name but my filesystem definitely does. xD
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.
Note sure we really need to guard against this. What is your opinion?
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.
Seems unnecessary
to address issue #34