Skip to content
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
Next Next commit
no periods in new contract names
  • Loading branch information
trace-andreason committed Feb 21, 2021
commit bce05026fe73b9095ab082da2c204a79c15858e0
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