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

no periods in new contract names #192

Merged
merged 3 commits into from
Feb 24, 2021

Conversation

trace-andreason
Copy link
Contributor

to address issue #34

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('.') {
Copy link
Collaborator

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.

@trace-andreason
Copy link
Contributor Author

@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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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)

Copy link
Contributor Author

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

Copy link
Collaborator

@ascjones ascjones left a 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 == '_') {
Copy link
Contributor

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?

Copy link
Collaborator

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?

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems unnecessary

@ascjones ascjones merged commit 967aa37 into use-ink:master Feb 24, 2021
@ascjones ascjones mentioned this pull request Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants