Fixed #28165 -- Ignored case in FileExtensionValidator's allowed_extensions.
This commit is contained in:
parent
b137add6cf
commit
681d2599ee
|
@ -461,6 +461,8 @@ class FileExtensionValidator:
|
||||||
code = 'invalid_extension'
|
code = 'invalid_extension'
|
||||||
|
|
||||||
def __init__(self, allowed_extensions=None, message=None, code=None):
|
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
|
self.allowed_extensions = allowed_extensions
|
||||||
if message is not None:
|
if message is not None:
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|
|
@ -286,6 +286,7 @@ to, or in lieu of custom ``field.clean()`` methods.
|
||||||
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
|
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
|
||||||
``'invalid_extension'`` if the extension of ``value.name`` (``value`` is
|
``'invalid_extension'`` if the extension of ``value.name`` (``value`` is
|
||||||
a :class:`~django.core.files.File`) isn't found in ``allowed_extensions``.
|
a :class:`~django.core.files.File`) isn't found in ``allowed_extensions``.
|
||||||
|
The extension is compared case-insensitively with ``allowed_extensions``.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
|
|
|
@ -256,6 +256,7 @@ TEST_DATA = [
|
||||||
(FileExtensionValidator(['']), ContentFile('contents', name='fileWithNoExtension'), None),
|
(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(['txt']), ContentFile('contents', name='file.TXT'), None),
|
||||||
|
(FileExtensionValidator(['TXT']), ContentFile('contents', name='file.txt'), None),
|
||||||
(FileExtensionValidator(), ContentFile('contents', name='file.jpg'), None),
|
(FileExtensionValidator(), ContentFile('contents', name='file.jpg'), None),
|
||||||
|
|
||||||
(validate_image_file_extension, 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']),
|
||||||
FileExtensionValidator(['txt'])
|
FileExtensionValidator(['txt'])
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
FileExtensionValidator(['TXT']),
|
||||||
|
FileExtensionValidator(['txt'])
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
FileExtensionValidator(['TXT', 'png']),
|
||||||
|
FileExtensionValidator(['txt', 'png'])
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
FileExtensionValidator(['txt']),
|
FileExtensionValidator(['txt']),
|
||||||
FileExtensionValidator(['txt'], code='invalid_extension')
|
FileExtensionValidator(['txt'], code='invalid_extension')
|
||||||
|
|
Loading…
Reference in New Issue