#34920: Reordered file extensions for improved validation
------------------------------+--------------------------------------
     Reporter:  ksg97031      |                    Owner:  nobody
         Type:  Bug           |                   Status:  new
    Component:  Core (Other)  |                  Version:  dev
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Unreviewed
    Has patch:  1             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+--------------------------------------
Description changed by ksg97031:

Old description:

> `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.

New description:

 `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.

 {{{
 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:

 {{{
 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#comment:1>
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/0107018b535de9f8-b834640d-2bd0-4cf3-8fd4-1ef86d3d8916-000000%40eu-central-1.amazonses.com.

Reply via email to