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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/cmd/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

anyhow::bail!("Contract names cannot contain periods");
}

if name.contains('-') {
anyhow::bail!("Contract names cannot contain hyphens");
}
Expand Down Expand Up @@ -114,6 +118,19 @@ mod tests {
})
}

#[test]
fn rejects_name_with_period() {
with_tmp_dir(|path| {
let result = execute("../xxx", Some(path));
assert!(result.is_err(), "Should fail");
assert_eq!(
result.err().unwrap().to_string(),
"Contract names cannot contain periods"
);
Ok(())
})
}

#[test]
fn contract_cargo_project_already_exists() {
with_tmp_dir(|path| {
Expand Down