Ticket #18761: ticket_18761.diff

File ticket_18761.diff, 1.3 KB (added by Melevir, 3 years ago)

Added stripping for URLField, IPAddressField, GenericIPAddressField, SlugField. I have two questions: is it all that should be done? Why no tests are required?

  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index 4438812..7e41d6e 100644
    a b class URLField(CharField): 
    600600
    601601        value = super(URLField, self).to_python(value)
    602602        if value:
    603             url_fields = split_url(value)
     603            url_fields = split_url(value.strip())
    604604            if not url_fields[0]:
    605605                # If no URL scheme given, assume http://
    606606                url_fields[0] = 'http'
    class IPAddressField(CharField): 
    988988    }
    989989    default_validators = [validators.validate_ipv4_address]
    990990
     991    def to_python(self, value):
     992        return value.strip()
    991993
    992994class GenericIPAddressField(CharField):
    993995    default_error_messages = {}
    class GenericIPAddressField(CharField): 
    10031005        if value in validators.EMPTY_VALUES:
    10041006            return ''
    10051007        if value and ':' in value:
    1006                 return clean_ipv6_address(value,
     1008                return clean_ipv6_address(value.strip(),
    10071009                    self.unpack_ipv4, self.error_messages['invalid'])
    10081010        return value
    10091011
    class SlugField(CharField): 
    10141016                     " underscores or hyphens."),
    10151017    }
    10161018    default_validators = [validators.validate_slug]
     1019
     1020    def to_python(self, value):
     1021        return value.strip()
Back to Top