1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #28165 -- Ignored case in FileExtensionValidator's allowed_extensions.

This commit is contained in:
Arne de Laat 2017-06-06 10:57:08 +02:00 committed by Tim Graham
parent b137add6cf
commit 681d2599ee
3 changed files with 12 additions and 0 deletions

View File

@ -461,6 +461,8 @@ class FileExtensionValidator:
code = 'invalid_extension'
def __init__(self, allowed_extensions=None, message=None, code=None):
if allowed_extensions is not None:
allowed_extensions = [allowed_extension.lower() for allowed_extension in allowed_extensions]
self.allowed_extensions = allowed_extensions
if message is not None:
self.message = message

View File

@ -286,6 +286,7 @@ to, or in lieu of custom ``field.clean()`` methods.
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
``'invalid_extension'`` if the extension of ``value.name`` (``value`` is
a :class:`~django.core.files.File`) isn't found in ``allowed_extensions``.
The extension is compared case-insensitively with ``allowed_extensions``.
.. warning::

View File

@ -256,6 +256,7 @@ TEST_DATA = [
(FileExtensionValidator(['']), ContentFile('contents', name='fileWithNoExtension'), None),
(FileExtensionValidator(['txt']), ContentFile('contents', name='file.txt'), None),
(FileExtensionValidator(['txt']), ContentFile('contents', name='file.TXT'), None),
(FileExtensionValidator(['TXT']), ContentFile('contents', name='file.txt'), None),
(FileExtensionValidator(), ContentFile('contents', name='file.jpg'), None),
(validate_image_file_extension, ContentFile('contents', name='file.jpg'), None),
@ -458,6 +459,14 @@ class TestValidatorEquality(TestCase):
FileExtensionValidator(['txt']),
FileExtensionValidator(['txt'])
)
self.assertEqual(
FileExtensionValidator(['TXT']),
FileExtensionValidator(['txt'])
)
self.assertEqual(
FileExtensionValidator(['TXT', 'png']),
FileExtensionValidator(['txt', 'png'])
)
self.assertEqual(
FileExtensionValidator(['txt']),
FileExtensionValidator(['txt'], code='invalid_extension')