Don't let ALLOWED_INCLUDE_ROOTS be accidentally set to a string rather than a tuple. Thanks to Florian Apolloner for pointing this out.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17571 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Chris Beaven 2012-02-22 00:42:19 +00:00
parent a3bb4df895
commit 3ac0961e1e
3 changed files with 15 additions and 2 deletions

View File

@ -73,6 +73,9 @@ class BaseSettings(object):
elif name == "ADMIN_MEDIA_PREFIX": elif name == "ADMIN_MEDIA_PREFIX":
warnings.warn("The ADMIN_MEDIA_PREFIX setting has been removed; " warnings.warn("The ADMIN_MEDIA_PREFIX setting has been removed; "
"use STATIC_URL instead.", DeprecationWarning) "use STATIC_URL instead.", DeprecationWarning)
elif name == "ALLOWED_INCLUDE_ROOTS" and isinstance(value, basestring):
raise ValueError("The ALLOWED_INCLUDE_ROOTS setting must be set "
"to a tuple, not a string.")
object.__setattr__(self, name, value) object.__setattr__(self, name, value)
@ -98,7 +101,8 @@ class Settings(BaseSettings):
for setting in dir(mod): for setting in dir(mod):
if setting == setting.upper(): if setting == setting.upper():
setting_value = getattr(mod, setting) setting_value = getattr(mod, setting)
if setting in tuple_settings and type(setting_value) == str: if setting in tuple_settings and \
isinstance(setting_value, basestring):
setting_value = (setting_value,) # In case the user forgot the comma. setting_value = (setting_value,) # In case the user forgot the comma.
setattr(self, setting, setting_value) setattr(self, setting, setting_value)

View File

@ -150,6 +150,13 @@ class SettingsTests(TestCase):
def test_settings_delete_wrapped(self): def test_settings_delete_wrapped(self):
self.assertRaises(TypeError, delattr, settings, '_wrapped') self.assertRaises(TypeError, delattr, settings, '_wrapped')
def test_allowed_include_roots_string(self):
"""
ALLOWED_INCLUDE_ROOTS is not allowed to be incorrectly set to a string
rather than a tuple.
"""
self.assertRaises(ValueError, setattr, settings,
'ALLOWED_INCLUDE_ROOTS', '/var/www/ssi/')
class TrailingSlashURLTests(TestCase): class TrailingSlashURLTests(TestCase):

View File

@ -425,7 +425,9 @@ class Templates(unittest.TestCase):
#Set ALLOWED_INCLUDE_ROOTS so that ssi works. #Set ALLOWED_INCLUDE_ROOTS so that ssi works.
old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS
settings.ALLOWED_INCLUDE_ROOTS = os.path.dirname(os.path.abspath(__file__)) settings.ALLOWED_INCLUDE_ROOTS = (
os.path.dirname(os.path.abspath(__file__)),
)
# Warm the URL reversing cache. This ensures we don't pay the cost # Warm the URL reversing cache. This ensures we don't pay the cost
# warming the cache during one of the tests. # warming the cache during one of the tests.