Opened 12 years ago
Last modified 7 years ago
#18119 new New feature
add DomainNameValidator to validate Internet Domain Names
Reported by: | michele | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | validators |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (2)
Change History (9)
Changed 12 years ago by
Attachment: | domainnamevalidator.txt added |
---|
comment:1 Changed 12 years ago by
Needs documentation: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Changed 12 years ago by
Attachment: | domainnamevalidator_2.txt added |
---|
DomainNameValidator patch #2 - remove validator-own attributes before super()
comment:2 Changed 12 years ago by
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
comment:3 Changed 9 years ago by
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
Version: | 1.4 → master |
comment:4 Changed 9 years ago by
Patch needs improvement: | set |
---|
This is blocked on #20003. Patch will need to be updated after that change.
comment:7 Changed 7 years ago by
Patch needs improvement: | set |
---|
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 useself.accept_idna = kwargs.pop('accept_idna', True)