Django

Code

Changeset 6152

Show
Ignore:
Timestamp:
09/13/07 21:11:24 (11 months ago)
Author:
russellm
Message:

Fixed #3421 -- Added IP and localhost validation to newforms URLField. Thanks, SmileyChris?.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/fields.py

    r6096 r6152  
    336336            ugettext(u'Enter a valid e-mail address.'), *args, **kwargs) 
    337337 
    338 url_re = re.compile( 
    339     r'^https?://' # http:// or https:// 
    340     r'(?:[A-Z0-9-]+\.)+[A-Z]{2,6}' # domain 
    341     r'(?::\d+)?' # optional port 
    342     r'(?:/?|/\S+)$', re.IGNORECASE) 
    343  
    344338try: 
    345339    from django.conf import settings 
     
    399393            raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image.")) 
    400394        return f 
     395 
     396url_re = re.compile( 
     397    r'^https?://' # http:// or https:// 
     398    r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain... 
     399    r'localhost|' #localhost... 
     400    r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip 
     401    r'(?::\d+)?' # optional port 
     402    r'(?:/?|/\S+)$', re.IGNORECASE) 
    401403 
    402404class URLField(RegexField): 
  • django/trunk/tests/regressiontests/forms/tests.py

    r6151 r6152  
    16081608... 
    16091609ValidationError: [u'This field is required.'] 
     1610>>> f.clean('http://localhost') 
     1611u'http://localhost' 
    16101612>>> f.clean('http://example.com') 
    16111613u'http://example.com' 
    16121614>>> f.clean('http://www.example.com') 
    16131615u'http://www.example.com' 
     1616>>> f.clean('http://www.example.com:8000/test') 
     1617u'http://www.example.com:8000/test' 
     1618>>> f.clean('http://200.8.9.10') 
     1619u'http://200.8.9.10' 
     1620>>> f.clean('http://200.8.9.10:8000/test') 
     1621u'http://200.8.9.10:8000/test' 
    16141622>>> f.clean('foo') 
    16151623Traceback (most recent call last):