#28165: FileExtensionValidator's allowed_extensions must be given in lower case
-------------------------------------+-------------------------------------
Reporter: Arne de | Owner: nobody
Laat |
Type: Bug | Status: new
Component: File | Version: 1.11
uploads/storage | Keywords: validators
Severity: Normal | filefield
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Using any uppercase character for an 'allowed_extension' prevents it from
being matched. Because the input filename is being lowered before
comparison to the extensions.
Here is an example:
{{{
#!python
from django.core.validators import FileExtensionValidator
from collections import namedtuple
valid = FileExtensionValidator(['pdf', 'png'])
File = namedtuple('File', ['name'])
# valid: different case in file name
named_file = File(name='myfile.PDF')
valid(named_file)
named_file = File(name='myfile.PdF')
valid(named_file)
# using uppercase in validator
valid = FileExtensionValidator(['PDF', 'PNG'])
# invalid: everything, because the case of the input is lowered
named_file = File(name='myfile.PDF')
valid(named_file)
# ValidationError: ["File extension 'pdf' is not allowed. Allowed
extensions are: 'PDF, PNG'."]
named_file = File(name='myfile.pdf')
valid(named_file)
# ValidationError: ["File extension 'pdf' is not allowed. Allowed
extensions are: 'PDF, PNG'."]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28165>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.35a57b0eb7b22baf34b98060b55bb286%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.