I am using a subclassed Django URLField to perform some validation on clicked URLs. I added mailto as one of the supported URLValidator default_validators:
class MyURLField(forms.URLField):
default_validators = [
validators.URLValidator(
schemes=['http', 'https', 'ftp', 'ftps', 'mailto']
)
]
class MyForm(forms.Form):
url = MyURLField(required=True)
form = MyForm({'url': 'mailto:test@example.com'})
if not form.is_valid():
raise Exception()
clean_url = form.cleaned_data['url']
print(clean_url) # this prints 'mailto://test@example.com'
Is a mailto URL still valid with the two extra protocol slashes?
mailto:test@example.com versus mailto://test@example.com (what Django produces)