#34920: Reordered file extensions for improved validation
----------------------------------------+------------------------
               Reporter:  ksg97031      |          Owner:  nobody
                   Type:  Bug           |         Status:  new
              Component:  Core (Other)  |        Version:  dev
               Severity:  Normal        |       Keywords:
           Triage Stage:  Unreviewed    |      Has patch:  1
    Needs documentation:  0             |    Needs tests:  0
Patch needs improvement:  0             |  Easy pickings:  0
                  UI/UX:  0             |
----------------------------------------+------------------------
 `django.core.validators.FileExtensionValidator` had an '__eq__' method to
 compare the validator class. However, comparing arrays is not accurate
 when the order of elements in the arrays is different.

 ```python
 def __eq__(self, other):
     return (
         isinstance(other, self.__class__)
         and sorted(self.allowed_extensions) ==
 sorted(other.allowed_extensions)
         and self.message == other.message
         and self.code == other.code
     )
 ```

 This test case failed:

 ```python
 self.assertEqual(
     FileExtensionValidator(["jpg", "png", "txt"]),
     FileExtensionValidator(["txt", "jpg", "png"]),
 )
 ```

 So I suggest comparing two extension arrays after sorting them.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34920>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018b535d2099-27e2842c-f700-4612-9db9-c740258e5cc9-000000%40eu-central-1.amazonses.com.

Reply via email to