Ticket #6717: 6717-url-strip-v2-with-tests.diff

File 6717-url-strip-v2-with-tests.diff, 1.1 KB (added by Antti Kaihola, 17 years ago)

revised patch: handles None correctly, includes unit tests

  • django/newforms/fields.py

     
    505505        self.user_agent = validator_user_agent
    506506
    507507    def clean(self, value):
     508        if isinstance(value, basestring):
     509            value = value.strip()
    508510        # If no URL scheme given, assume http://
    509511        if value and '://' not in value:
    510512            value = u'http://%s' % value
  • tests/regressiontests/forms/fields.py

     
    923923>>> f.clean('https://example.com')
    924924u'https://example.com'
    925925
     926URLField should strip leading and trailing space before validation.
     927>>> f = URLField(required=False)
     928>>> f.clean('  http://example.com')
     929u'http://example.com'
     930>>> f.clean('http://example.com  ')
     931u'http://example.com'
     932>>> f.clean('  ')
     933u''
     934
    926935# BooleanField ################################################################
    927936
    928937>>> f = BooleanField()
Back to Top