Author: adrian
Date: 2008-09-16 00:39:49 -0500 (Tue, 16 Sep 2008)
New Revision: 9043

Modified:
   django/trunk/django/core/management/base.py
Log:
Fixed #9092 -- Improved validation of app/project names by 
startapp/startproject so that it doesn't allow names to start with a number.

Modified: django/trunk/django/core/management/base.py
===================================================================
--- django/trunk/django/core/management/base.py 2008-09-16 05:31:00 UTC (rev 
9042)
+++ django/trunk/django/core/management/base.py 2008-09-16 05:39:49 UTC (rev 
9043)
@@ -194,8 +194,13 @@
     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)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to