From 883aa6b9c8070d6946435c5f9783a49511830367 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 16 Sep 2008 05:39:49 +0000 Subject: [PATCH] Fixed #9092 -- Improved validation of app/project names by startapp/startproject 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 --- django/core/management/base.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django/core/management/base.py b/django/core/management/base.py index 20cc7c0f40..f20466f89e 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -194,8 +194,13 @@ def copy_helper(style, app_or_project, name, directory, other_name=''): import re import shutil other = {'project': 'app', 'app': 'project'}[app_or_project] - if not re.search(r'^\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)) + if not re.search(r'^[_a-zA-Z]\w*$', name): # If it's not a valid directory name. + # 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) try: os.mkdir(top_dir)