-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
refactor: forc init
generate unexpected project_name when project dir contains dot
#5455
Conversation
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.
Thanks for the PR! I will test this locally but it seems like this will allow project with .
in the name, which is not something we should be doing imo. Blocking for now so that I can test
The |
I think we should disallow project names with dots or any special character other than Here's a regex we can use: |
If I understood correctly, the suggested changes are to revert the logic of getting project_name and add a new regex |
Yes, I think that's the best path forward. If it doesn't match the regex, we can show an error like "The project name can be a combination of letters, numbers and underscores, and must start with a letter." |
@sdankel For the reason above, I think we should add a new function pub fn validate_project_name(name: &str) -> Result<()> {
let re = Regex::new(r"^([a-zA-Z]([a-zA-Z0-9-_]+)|)$").unwrap();
if !re.is_match(name) {
bail!(
"the project name `{name}` cannot be used as a project name.\n\
project name can be a combination of letters, numbers, hyphen, and underscores, \
and must start with a letter."
);
}
validate_name(name, "project name")
} BTW, is the '-' hyphen valid in the project name? |
Yes, good catch!
I don't think there is a difference between package name and project name. I agree that organization name should not have this validation. |
Suggestion changes done~ |
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.
Looks good, thanks!
Can we get this merged now? Is there anything else that needs to be added? |
Description
Refer #5434
Found this issue when I tried to run
forc init --script
under a directory(/tmp/path_with_._dot
) that contains a dot ".". The value ofproject.name
in the generated fileForc.toml
is truncated by the dot "." aspath_with_
.Since
project_dir
must be a directory(has checked before), we can usefile_name
instead offile_stem
to get the last-level dir name. Also, I think it would be better to replace "." with "_", otherwise aproject_name
that contains.
would fail with validationvalidate_name(&project_name, "project name")?;
Screenshots
Before:
After:
Checklist
Breaking*
orNew Feature
labels where relevant.