diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-09-14 02:11:24 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-09-14 02:11:24 +0000 |
| commit | a2ce7669d902cf32eeac9307b804b78ed4150fe5 (patch) | |
| tree | 2d82420bd2991f237befa0fefadde0bb869a07f8 /django/newforms/fields.py | |
| parent | 8b0eaba0ee66e2ec6307ae9e34cf8610614d67a6 (diff) | |
Fixed #3421 -- Added IP and localhost validation to newforms URLField. Thanks, SmileyChris.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6152 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/fields.py')
| -rw-r--r-- | django/newforms/fields.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/django/newforms/fields.py b/django/newforms/fields.py index a98779a334..fc816a842b 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -335,12 +335,6 @@ class EmailField(RegexField): RegexField.__init__(self, email_re, max_length, min_length, ugettext(u'Enter a valid e-mail address.'), *args, **kwargs) -url_re = re.compile( - r'^https?://' # http:// or https:// - r'(?:[A-Z0-9-]+\.)+[A-Z]{2,6}' # domain - r'(?::\d+)?' # optional port - r'(?:/?|/\S+)$', re.IGNORECASE) - try: from django.conf import settings URL_VALIDATOR_USER_AGENT = settings.URL_VALIDATOR_USER_AGENT @@ -399,6 +393,14 @@ class ImageField(FileField): raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image.")) return f +url_re = re.compile( + r'^https?://' # http:// or https:// + r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain... + r'localhost|' #localhost... + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip + r'(?::\d+)?' # optional port + r'(?:/?|/\S+)$', re.IGNORECASE) + class URLField(RegexField): def __init__(self, max_length=None, min_length=None, verify_exists=False, validator_user_agent=URL_VALIDATOR_USER_AGENT, *args, **kwargs): |
