Browse Source

Fixed #34943 -- Made EmailValidator.__eq__() ignore domain_allowlist ordering.

Signed-off-by: ksg97031 <ksg97031@gmail.com>
ksg 1 year ago
parent
commit
a6c7db1d1d
2 changed files with 5 additions and 1 deletions
  1. 1 1
      django/core/validators.py
  2. 4 0
      tests/validators/tests.py

+ 1 - 1
django/core/validators.py

@@ -244,7 +244,7 @@ class EmailValidator:
     def __eq__(self, other):
         return (
             isinstance(other, EmailValidator)
-            and (self.domain_allowlist == other.domain_allowlist)
+            and (set(self.domain_allowlist) == set(other.domain_allowlist))
             and (self.message == other.message)
             and (self.code == other.code)
         )

+ 4 - 0
tests/validators/tests.py

@@ -750,6 +750,10 @@ class TestValidatorEquality(TestCase):
             EmailValidator(message="BAD EMAIL", code="bad"),
             EmailValidator(message="BAD EMAIL", code="bad"),
         )
+        self.assertEqual(
+            EmailValidator(allowlist=["127.0.0.1", "localhost"]),
+            EmailValidator(allowlist=["localhost", "127.0.0.1"]),
+        )
 
     def test_basic_equality(self):
         self.assertEqual(