Code

Opened 4 years ago

Closed 4 years ago

#13744 closed (duplicate)

URLValidator doesnt add "http://" to the beginning of url string if user forgets to write it

Reported by: michaelhjulskov Owned by: nobody
Component: Forms Version: 1.2-alpha
Severity: Keywords: URLValidator
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by Alex)

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

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by Alex

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Please use the preview button, and consult WikiFormatting before posting.

comment:2 Changed 4 years ago by john_scott

  • Resolution set to duplicate
  • Status changed from new to closed

Closing this as a duplicate of #13613

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.