Opened 13 months ago
Last modified 13 months ago
#34920 closed Bug
Reordered file extensions for improved validation — at Initial Version
Reported by: | ksg | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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.