[Django] #18119: add DomainNameValidator to validate Internet Domain Names

59 views
Skip to first unread message

Django

unread,
Apr 13, 2012, 5:39:09 AM4/13/12
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+------------------------
Reporter: michele | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.4
Severity: Normal | Keywords: validators
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------
Internet Domain Names are very present throughout, e.g. in URLs and e-mail
addresses.

This patch adds django.core.validators.DomainNameValidator to check
Internet Domain Names.

DomainNameValidator supports IDNA (utf) domain names, but it can reject
them if optional accept_idna=False is passed to the constructor (defaults
to accept).

DomainNameValidator is implemented as follows:
* derives RegexValidator
* uses the same RegEx of URLValidator (with the additional constrain to
accept only 127 labels / 255 chars, as per RFC)
* if plain validation fails, converts UTF -> ASCII with IDNA encoding and
attempts to validate again (unless accept_idna=False)

Based on this Validator, I will submit separate patches to add
DomainNameField support for models.

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

Django

unread,
Apr 13, 2012, 6:34:53 AM4/13/12
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+------------------------------------
Reporter: michele | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.4
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by claudep):

* needs_docs: => 1
* needs_better_patch: => 1
* needs_tests: => 1
* stage: Unreviewed => Accepted


Comment:

I think it is a good idea to centralize domain name validation. I detected
at least three points where we could use this validator
(django/core/mail/message.py, django/core/validators.py (URLValidator),
django/utils/html.py).

For DRY reasons, the domain regex part should be shared with URLValidator.
In `__init__`, just use {{{self.accept_idna = kwargs.pop('accept_idna',
True)}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:1>

Django

unread,
Apr 13, 2012, 7:46:39 AM4/13/12
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+------------------------------------
Reporter: michele | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.4
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by michele):

In attachment:domainnamevalidator_2.txt :

* fix the constructor argument as per claudep suggestion
* return a specific error message based on IDNA being accepted or not

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:2>

Django

unread,
Nov 6, 2014, 2:31:38 PM11/6/14
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+------------------------------------

Reporter: michele | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: master

Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by berkerpeksag):

* needs_better_patch: 1 => 0
* version: 1.4 => master
* needs_tests: 1 => 0
* needs_docs: 1 => 0


Comment:

https://github.com/django/django/pull/3477

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:3>

Django

unread,
Dec 24, 2014, 4:21:06 PM12/24/14
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+------------------------------------

Reporter: michele | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

This is blocked on #20003. Patch will need to be updated after that
change.

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:4>

Django

unread,
Mar 4, 2016, 4:58:14 AM3/4/16
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+------------------------------------

Reporter: michele | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by guettli):

would be nice to have

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:5>

Django

unread,
Sep 26, 2016, 9:58:49 PM9/26/16
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+------------------------------------

Reporter: michele | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Berker Peksag):

* needs_better_patch: 1 => 0


Comment:

Updated [https://github.com/django/django/pull/7300 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:6>

Django

unread,
Oct 4, 2016, 2:19:27 PM10/4/16
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+------------------------------------

Reporter: michele | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:7>

Django

unread,
Jan 29, 2024, 8:46:17 AM1/29/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev

Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Nina Menezes):

* owner: nobody => Nina Menezes
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:8>

Django

unread,
Mar 31, 2024, 4:15:29 PM3/31/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Comment (by Nina Menezes):

New PR: https://github.com/django/django/pull/18037.
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:9>

Django

unread,
Apr 1, 2024, 8:35:05 AM4/1/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 1 => 0

Comment:

Thank you Nina for working on this! I have unset the `patch needs
improvement` flag so this is listed in the "needs review" list in the
[https://dashboard.djangoproject.com/ dashboard].
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:10>

Django

unread,
Apr 8, 2024, 5:09:25 AM4/8/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1
* needs_docs: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:11>

Django

unread,
Apr 20, 2024, 6:24:43 PM4/20/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Nina Menezes):

* needs_better_patch: 1 => 0
* needs_docs: 1 => 0

Comment:

Documentation now updated.
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:12>

Django

unread,
May 6, 2024, 4:55:22 AM5/6/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:13>

Django

unread,
May 11, 2024, 2:18:05 PM5/11/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Nina Menezes):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:14>

Django

unread,
May 13, 2024, 3:41:58 AM5/13/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:15>

Django

unread,
May 15, 2024, 2:58:59 AM5/15/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Comment (by Claude Paroz):

Somewhat naive question: are there still use cases to exclude IDNA domain
names from such a validator, 12 years after the initial report?
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:16>

Django

unread,
May 19, 2024, 2:26:45 PM5/19/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Nina Menezes):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:17>

Django

unread,
May 21, 2024, 6:52:14 AM5/21/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Comment (by Sarah Boyce):

Replying to [comment:16 Claude Paroz]:
> Somewhat naive question: are there still use cases to exclude IDNA
domain names from such a validator, 12 years after the initial report?

Good question, perhaps it makes sense to remove the `accept_idna` argument
and not support excluding IDNA domain names for now. Then if someone has a
use case this can be raised in a new ticket?
Nina - what do you think?
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:18>

Django

unread,
May 21, 2024, 6:53:46 AM5/21/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

Comment:

(open question as to whether we should drop `accept_idna`)
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:19>

Django

unread,
May 21, 2024, 7:11:09 AM5/21/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
------------------------------+----------------------------------------
Reporter: michele | Owner: Nina Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Comment (by mij):

The reason for adding accept_idna had nothing to do with how "modern" the
format was. It's a way to allow the developer to enforce ascii names.

Although python beautifully supports UTF, the developer is often required
to handle non-ascii characters specially. For example, when checking their
length, or storing them somewhere, or serializing them to somewhere else.
The exceeding rarity of IDNA causes many to assume the domain is ASCII,
only to run into exception later in production.

If not else, the presence of the accept_idna option forces the developer
to think whether that's a relevant case for them, and what to do about it.

I wouldn't necessarily consider adding it if the patch was without, but I
certainly see value in keeping it now it's already there.

PS: I'm the original submitter. Trac wouldn't send me a reset-password
link.
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:20>

Django

unread,
May 21, 2024, 10:58:04 AM5/21/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
-------------------------------------+-------------------------------------
Reporter: michele | Owner: Nina
| Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

Comment:

Replying to [comment:20 michele]:
> I wouldn't necessarily consider adding it if the patch was without, but
I certainly see value in keeping it now it's already there.
>
> PS: I'm the original submitter. Trac wouldn't send me a reset-password
link.

Thank you for your input. In which case, I am marking the patch as "Ready
for checkin".
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:21>

Django

unread,
May 21, 2024, 4:55:29 PM5/21/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
-------------------------------------+-------------------------------------
Reporter: michele | Owner: Nina
| Menezes
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: validators | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Claude Paroz):

OK, let's go for it, at least the parameter default is `True`.
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:22>

Django

unread,
May 21, 2024, 5:11:22 PM5/21/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
-------------------------------------+-------------------------------------
Reporter: michele | Owner: Nina
| Menezes
Type: New feature | Status: closed
Component: Core (Other) | Version: dev
Severity: Normal | Resolution: fixed
Keywords: validators | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"4971a9afe5642569f3dcfcd3972ebb39e88dd457" 4971a9a]:
{{{#!CommitTicketReference repository=""
revision="4971a9afe5642569f3dcfcd3972ebb39e88dd457"
Fixed #18119 -- Added a DomainNameValidator validator.

Thanks Claude Paroz for the review.

Co-authored-by: Nina Menezes <77671865+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:23>

Django

unread,
Dec 13, 2024, 10:10:44 AM12/13/24
to django-...@googlegroups.com
#18119: add DomainNameValidator to validate Internet Domain Names
-------------------------------------+-------------------------------------
Reporter: michele | Owner: Nina
| Menezes
Type: New feature | Status: closed
Component: Core (Other) | Version: dev
Severity: Normal | Resolution: fixed
Keywords: validators | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"54059125956789ad4c19b77eb7f5cde76eec0643" 5405912]:
{{{#!CommitTicketReference repository=""
revision="54059125956789ad4c19b77eb7f5cde76eec0643"
Fixed #36007 -- Removed dead code from URLValidator.

The "Trivial case failed. Try for possible IDN domain" handling was
obsoleted by ticket-20003, which adjusted the regular expressions to
allow all international domain names (Refs #20003).

Uses of `ul` were moved to DomainNameValidator in ticket-18119
(Refs #18119).
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/18119#comment:24>
Reply all
Reply to author
Forward
0 new messages