#13744: URLValidator doesnt add "http://"; to the beginning of url string if user
forgets to write it
-----------------------------+----------------------------------------------
 Reporter:  michaelhjulskov  |       Owner:  nobody    
   Status:  new              |   Milestone:            
Component:  Forms            |     Version:  1.2-alpha 
 Keywords:  URLValidator     |       Stage:  Unreviewed
Has_patch:  0                |  
-----------------------------+----------------------------------------------
 from django.forms.fields import URLField
 from django.core.validators import URLValidator

 class MyURLValidator(URLValidator):
     regex = re.compile(
         r'^(?:https?://)?' # http:// or https://
         r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[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 MyURLField(URLField):
     def __init__(self, max_length=None, min_length=None,
 verify_exists=False,
 validator_user_agent=validators.URL_VALIDATOR_USER_AGENT, *args,
 **kwargs):
         super(MyURLField, self).__init__(max_length, min_length, *args,
 **kwargs)
         self.validators.append(MyURLValidator(verify_exists=verify_exists,
 validator_user_agent=validator_user_agent))

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13744>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
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.

Reply via email to