Ticket #9948: urlfield-r9692.diff

File urlfield-r9692.diff, 1.7 KB (added by Ivan Giuliani, 16 years ago)
  • django/forms/fields.py

     
    527527
    528528url_re = re.compile(
    529529    r'^https?://' # http:// or https://
    530     r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain...
     530    r'(?:(?:[A-Z0-9]+(?:-[A-Z0-9]+)*\.)+[A-Z]{2,6}|' #domain...
    531531    r'localhost|' #localhost...
    532532    r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
    533533    r'(?::\d+)?' # optional port
  • tests/regressiontests/forms/fields.py

     
    864864u'http://www.example.com/'
    865865>>> f.clean('http://www.example.com:8000/test')
    866866u'http://www.example.com:8000/test'
     867>>> f.clean('valid-with-hyphens.com')
     868u'http://valid-with-hyphens.com/'
     869>>> f.clean('subdomain.domain.com')
     870u'http://subdomain.domain.com/'
    867871>>> f.clean('http://200.8.9.10')
    868872u'http://200.8.9.10/'
    869873>>> f.clean('http://200.8.9.10:8000/test')
     
    888892Traceback (most recent call last):
    889893...
    890894ValidationError: [u'Enter a valid URL.']
     895>>> f.clean('http://invalid-.com')
     896Traceback (most recent call last):
     897...
     898ValidationError: [u'Enter a valid URL.']
     899>>> f.clean('inv-.alid-.com')
     900Traceback (most recent call last):
     901...
     902ValidationError: [u'Enter a valid URL.']
     903>>> f.clean('inv-.-alid.com')
     904Traceback (most recent call last):
     905...
     906ValidationError: [u'Enter a valid URL.']
     907>>> f.clean('inv-----alid.com')
     908Traceback (most recent call last):
     909...
     910ValidationError: [u'Enter a valid URL.']
     911 
    891912
    892913>>> f = URLField(required=False)
    893914>>> f.clean('')
Back to Top