Skip to content

Commit 0182521

Browse files
jamesobutlerjcfr
authored andcommitted
ENH: Add input validation for app name
1 parent a84a5fc commit 0182521

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

hooks/pre_gen_project.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import re
2+
import sys
3+
4+
APP_NAME_REGEX = r"^[a-zA-Z0-9]+$"
5+
6+
app_name = "{{ cookiecutter.app_name }}"
7+
8+
if not re.match(APP_NAME_REGEX, app_name):
9+
print(
10+
f"ERROR: {app_name} is not a valid app name. "
11+
"Only alphanumeric characters are allowed."
12+
)
13+
14+
# exits with status 1 to indicate failure
15+
sys.exit(1)

0 commit comments

Comments
 (0)