Ticket #17751: 17751-2.diff

File 17751-2.diff, 1.7 KB (added by Claude Paroz, 12 years ago)

Forbid whitespaces in ipv6 addresses

  • django/utils/ipv6.py

    diff --git a/django/utils/ipv6.py b/django/utils/ipv6.py
    index 7624bb9..4cce85e 100644
    a b  
    11# This code was mostly based on ipaddr-py
    22# Copyright 2007 Google Inc. http://code.google.com/p/ipaddr-py/
    33# Licensed under the Apache License, Version 2.0 (the "License").
     4import string
     5
    46from django.core.exceptions import ValidationError
    57from django.utils.six.moves import xrange
    68
    def is_valid_ipv6_address(ip_str):  
    154156    """
    155157    from django.core.validators import validate_ipv4_address
    156158
     159    # No whitespaces allowed
     160    if any(c in string.whitespace for c in ip_str):
     161        return False
     162
    157163    # We need to have at least one ':'.
    158164    if ':' not in ip_str:
    159165        return False
  • tests/modeltests/validators/tests.py

    diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py
    index 0174a60..84dc19c 100644
    a b TEST_DATA = (  
    6767    (validate_ipv4_address, '25.1.1.', ValidationError),
    6868    (validate_ipv4_address, '25,1,1,1', ValidationError),
    6969    (validate_ipv4_address, '25.1 .1.1', ValidationError),
     70    (validate_ipv4_address, ' 1.1.1.1', ValidationError),
    7071
    7172    # validate_ipv6_address uses django.utils.ipv6, which
    7273    # is tested in much greater detail in it's own testcase
    TEST_DATA = (  
    7778    (validate_ipv6_address, '1:2', ValidationError),
    7879    (validate_ipv6_address, '::zzz', ValidationError),
    7980    (validate_ipv6_address, '12345::', ValidationError),
     81    (validate_ipv6_address, ' fe80::1', ValidationError),
     82    (validate_ipv6_address, 'fe80       ::1', ValidationError),
    8083
    8184    (validate_ipv46_address, '1.1.1.1', None),
    8285    (validate_ipv46_address, '255.0.0.0', None),
Back to Top