Skip to content

Commit

Permalink
Fixed #9092 -- Improved validation of app/project names by startapp/s…
Browse files Browse the repository at this point in the history
…tartproject so that it doesn't allow names to start with a number.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9043 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Sep 16, 2008
1 parent 772639c commit 883aa6b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions django/core/management/base.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ def copy_helper(style, app_or_project, name, directory, other_name=''):
import re import re
import shutil import shutil
other = {'project': 'app', 'app': 'project'}[app_or_project] other = {'project': 'app', 'app': 'project'}[app_or_project]
if not re.search(r'^\w+$', name): # If it's not a valid directory name. if not re.search(r'^[_a-zA-Z]\w*$', name): # If it's not a valid directory name.
raise CommandError("%r is not a valid %s name. Please use only numbers, letters and underscores." % (name, app_or_project)) # Provide a smart error message, depending on the error.
if not re.search(r'^[_a-zA-Z]', name):
message = 'make sure the name begins with a letter or underscore'
else:
message = 'use only numbers, letters and underscores'
raise CommandError("%r is not a valid %s name. Please %s." % (name, app_or_project, message))
top_dir = os.path.join(directory, name) top_dir = os.path.join(directory, name)
try: try:
os.mkdir(top_dir) os.mkdir(top_dir)
Expand Down

0 comments on commit 883aa6b

Please sign in to comment.