Skip to content

no periods in new contract names#192

Merged
ascjones merged 3 commits into
use-ink:masterfrom
trace-andreason:periods-in-contract-names
Feb 24, 2021
Merged

no periods in new contract names#192
ascjones merged 3 commits into
use-ink:masterfrom
trace-andreason:periods-in-contract-names

Conversation

@trace-andreason

Copy link
Copy Markdown
Contributor

to address issue #34

Comment thread src/cmd/new.rs Outdated
where
P: AsRef<Path>,
{
if name.contains('.') {

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@ascjones good call, made that change and removed these invalid character checks.

Comment thread src/cmd/new.rs Outdated
{
if name.contains('-') {
anyhow::bail!("Contract names cannot contain hyphens");
if !name.replace('_', "").chars().all(char::is_alphanumeric) {

Copy link
Copy Markdown
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
Copy Markdown
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

@ascjones ascjones left a comment

Copy link
Copy Markdown
Collaborator

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?

Comment thread src/cmd/new.rs
{
if name.contains('-') {
anyhow::bail!("Contract names cannot contain hyphens");
if !name.chars().all(|c| c.is_alphanumeric() || c == '_') {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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