Author: russellm
Date: 2007-09-13 21:11:24 -0500 (Thu, 13 Sep 2007)
New Revision: 6152
Modified:
django/trunk/django/newforms/fields.py
django/trunk/tests/regressiontests/forms/tests.py
Log:
Fixed #3421 -- Added IP and localhost validation to newforms URLField. Thanks,
SmileyChris.
Modified: django/trunk/django/newforms/fields.py
===================================================================
--- django/trunk/django/newforms/fields.py 2007-09-14 02:05:45 UTC (rev
6151)
+++ django/trunk/django/newforms/fields.py 2007-09-14 02:11:24 UTC (rev
6152)
@@ -335,12 +335,6 @@
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 @@
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):
Modified: django/trunk/tests/regressiontests/forms/tests.py
===================================================================
--- django/trunk/tests/regressiontests/forms/tests.py 2007-09-14 02:05:45 UTC
(rev 6151)
+++ django/trunk/tests/regressiontests/forms/tests.py 2007-09-14 02:11:24 UTC
(rev 6152)
@@ -1607,10 +1607,18 @@
Traceback (most recent call last):
...
ValidationError: [u'This field is required.']
+>>> f.clean('http://localhost')
+u'http://localhost'
>>> f.clean('http://example.com')
u'http://example.com'
>>> f.clean('http://www.example.com')
u'http://www.example.com'
+>>> f.clean('http://www.example.com:8000/test')
+u'http://www.example.com:8000/test'
+>>> f.clean('http://200.8.9.10')
+u'http://200.8.9.10'
+>>> f.clean('http://200.8.9.10:8000/test')
+u'http://200.8.9.10:8000/test'
>>> f.clean('foo')
Traceback (most recent call last):
...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---