Fix LDAPServerURIField number in domain

- Bug: API error if LDAPServerURIField contains a number in the top level domain
- Add custom regex in LDAPServerURIField class that is passed to django
  URLValidator
- The custom regex allows for numbers to be present in the top level domain
- Unit tests check that valid URIs pass through URLValidator, and that
  invalid URIs raise the correct exception
- Related to issue #3646
This commit is contained in:
Seth Foster
2019-09-20 10:36:47 -04:00
parent 154cda7501
commit ca5de6378a
3 changed files with 44 additions and 0 deletions

View File

@@ -121,11 +121,14 @@ class URLField(CharField):
def __init__(self, **kwargs):
schemes = kwargs.pop('schemes', None)
regex = kwargs.pop('regex', None)
self.allow_plain_hostname = kwargs.pop('allow_plain_hostname', False)
super(URLField, self).__init__(**kwargs)
validator_kwargs = dict(message=_('Enter a valid URL'))
if schemes is not None:
validator_kwargs['schemes'] = schemes
if regex is not None:
validator_kwargs['regex'] = regex
self.validators.append(URLValidator(**validator_kwargs))
def to_representation(self, value):