Fixed #20003 -- Improved and extended URLValidator

This adds support for authentication data (`user:password`) in URLs,
IPv6 addresses, and unicode domains.

The test suite has been improved by adding test URLs from
http://mathiasbynens.be/demo/url-regex (with a few adjustments,
like allowing local and reserved IPs).

The previous URL validation regex failed this test suite on 13
occasions, the validator was updated based on
https://gist.github.com/dperini/729294.
This commit is contained in:
Danilo Bargen 2014-11-03 18:01:31 +01:00 committed by Tim Graham
parent 6288fccfda
commit 2e65d56156
6 changed files with 123 additions and 13 deletions

View file

@ -149,9 +149,13 @@ to, or in lieu of custom ``field.clean()`` methods.
.. class:: URLValidator([schemes=None, regex=None, message=None, code=None])
A :class:`RegexValidator` that ensures a value looks like a URL, and raises
an error code of ``'invalid'`` if it doesn't. In addition to the optional
arguments of its parent :class:`RegexValidator` class, ``URLValidator``
accepts an extra optional attribute:
an error code of ``'invalid'`` if it doesn't.
Loopback addresses and reserved IP spaces are considered valid. Literal
IPv6 addresses (:rfc:`2732`) and unicode domains are both supported.
In addition to the optional arguments of its parent :class:`RegexValidator`
class, ``URLValidator`` accepts an extra optional attribute:
.. attribute:: schemes
@ -165,6 +169,11 @@ to, or in lieu of custom ``field.clean()`` methods.
The optional ``schemes`` attribute was added.
.. versionchanged:: 1.8
Support for IPv6 addresses, unicode domains, and URLs containing
authentication data was added.
``validate_email``
------------------
.. data:: validate_email