Ticket #26378: 26378.1.diff

File 26378.1.diff, 1.5 KB (added by Amine Yaiche, 8 years ago)
  • django/utils/ipv6.py

    diff --git a/django/utils/ipv6.py b/django/utils/ipv6.py
    index 4f433d1..6e60959 100644
    a b def clean_ipv6_address(ip_str, unpack_ipv4=False,  
    5454
    5555    for index in range(len(hextets)):
    5656        # Remove leading zeroes
    57         hextets[index] = hextets[index].lstrip('0')
     57        if "." not in hextets[index]:
     58            hextets[index] = hextets[index].lstrip('0')
    5859        if not hextets[index]:
    5960            hextets[index] = '0'
    6061
  • tests/model_fields/tests.py

    diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
    index 70f039e..e444110 100644
    a b class GenericIPAddressFieldTests(test.TestCase):  
    904904        with self.assertRaises(ValidationError):
    905905            form_field.clean('127.0.0.1')
    906906
     907    def test_mixed_ipv46(self):
     908        """
     909        Test that GenericIPAddressField will accept a mixed IPv4 and IPv6 in all cases. See #26378.
     910        """
     911        unpack_ip_field = models.GenericIPAddressField(null=False, protocol='both', unpack_ipv4=True)
     912        not_unpack_ip_field = models.GenericIPAddressField(protocol='both', unpack_ipv4=False)
     913        unpack_ip_field.clean('::ffff:0.0.0.0', None)
     914        not_unpack_ip_field.clean('::ffff:0.0.0.0', None)
     915        not_unpack_ip_field.clean('::ffff:0.255.255.255', None)
     916        not_unpack_ip_field.clean('::ffff:1.0.0.0', None)
     917
     918
    907919    def test_null_value(self):
    908920        """
    909921        Null values should be resolved to None in Python (#24078).
Back to Top