Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #18119 -- Added a DomainNameValidator validator. #18037

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nmenezes0
Copy link
Contributor

@nmenezes0 nmenezes0 commented Mar 31, 2024

Trac ticket number

ticket-18119

Branch description

Provide a concise overview of the issue or rationale behind the proposed changes.
This ticket adds a DomainNameValidator to validate International domain names. This validator takes a flag is_idna (defaults to True) - to determine whether or not we should use non-ASCII international domain names.

This builds on the existing PR with some changes: not using IP addresses (don't think they are part of a domain name), removing changes to docs as out of date (not sure what updates are needed here now?), changes to the tests and how they were written, reusing the regex in URLValidator.

The ticket in Trac suggests that the regex could be reused elsewhere in the codebase. I have reused it in the URLValidator, but I couldn't see how to use it in django/core/mail/message.py or django/utils/html.py.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • For UI changes, I have attached screenshots in both light and dark modes. - N/A

I wasn't sure what changes I should make to the documentation.

@sarahboyce
Copy link
Contributor

Thank you for this Nina ⭐

removing changes to docs as out of date (not sure what updates are needed here now?)

All new features need some docs and a release note, so this is roughly what I am expecting:

  • Add DomainNameValidator to docs/ref/validators.txt with .. versionadded:: 5.1
  • Add a reference to this change in the 5.1 release notes

@nmenezes0 nmenezes0 force-pushed the feature/18119-domain-name-validation branch from fc3bd96 to f77f5f3 Compare April 20, 2024 21:45
@nmenezes0
Copy link
Contributor Author

Thanks Sarah - docs now updated.

docs/ref/validators.txt Outdated Show resolved Hide resolved
docs/ref/validators.txt Outdated Show resolved Hide resolved
docs/ref/validators.txt Outdated Show resolved Hide resolved
docs/releases/5.1.txt Show resolved Hide resolved
@nmenezes0
Copy link
Contributor Author

Thanks @felixxm - docs now updated following comments.

Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @nmenezes0 ⭐ I have a few more comments.
Please also squash this to a single commit 👍

docs/ref/validators.txt Outdated Show resolved Hide resolved
docs/ref/validators.txt Outdated Show resolved Hide resolved
ipv6_re = r"\[[0-9a-f:.]+\]" # (simple regex, validated later)

# Host patterns
# Max length for domain name labels is 63 characters per RFC 1034 sec. 3.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment # Max length for domain name labels is 63 characters per RFC 1034 sec. 3.1 should be above domain_re
I also think as this is best placed above the regex, we can remove the duplicate comment above domain_re = DomainNameValidator.domain_re in URLValidator
With a similar logic, add the # Host patterns comment here and remove the # Host patterns comment from above hostname_re = DomainNameValidator.hostname_re in URLValidator

Let's also add full stops to the end of the comments which are not inline (so # Host patterns. but maybe don't bother with the # can't end with a dash comments)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - comments in DomainNameValidator updated and relevant comments in URLValidator.

Comment on lines 142 to 144
# Host patterns
hostname_re = DomainNameValidator.hostname_re
# Max length for domain name labels is 63 characters per RFC 1034 sec. 3.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Host patterns
hostname_re = DomainNameValidator.hostname_re
# Max length for domain name labels is 63 characters per RFC 1034 sec. 3.1
hostname_re = DomainNameValidator.hostname_re

As per the above comment which hopefully makes sense

django/core/validators.py Outdated Show resolved Hide resolved
@@ -370,3 +370,28 @@ to, or in lieu of custom ``field.clean()`` methods.
.. versionchanged:: 5.0

The ``offset`` argument was added.

``DomainNameValidator``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's move the docs to be either under or above URLValidator to keep them close together

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now moved to above the URLValidator section.

@nmenezes0 nmenezes0 force-pushed the feature/18119-domain-name-validation branch from b2b5e90 to 151845f Compare May 11, 2024 17:53
Override __init__ function to add accept IDNA.

Updates to DomainNameValidator to add logic around accept_idna flag

Remove outdated details from docs.

Made changes to domain name validation and tests.

Reused regex in URLValidator.

Added more changes to the DomainNameValidator so all  tests pass.

Removed rogue space.

Blacken.

Update documentation for DomainNameValidator.

Remove unused text.

Tidy docs.

Update docs - fix underline.

Update docs/ref/validators.txt

Remove unnecessary blank lines.

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>

Update docs/releases/5.1.txt

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>

Changes to docs for DomainNameValidator.

Change name of the parameter.

Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>

Update docs for new naming.

Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>

Update django/core/validators.py

Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>

Update comments for validators.

Reorder docs to have DomainNameValidator next to URLNameValidator.

blacken
@nmenezes0 nmenezes0 force-pushed the feature/18119-domain-name-validation branch from 151845f to dd9816e Compare May 11, 2024 18:04
@nmenezes0
Copy link
Contributor Author

Thanks @sarahboyce - I've made those changes and squashed to a single commit.

@nmenezes0
Copy link
Contributor Author

I'm not sure why some of the checks are failing. The error is "commit changed" - potentially due to me pushing the squashed commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants