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 #25637 -- Added URLValidator hostname length validation. #5566

Closed
wants to merge 1 commit into from

Conversation

raphaelm
Copy link
Contributor

@raphaelm raphaelm commented Nov 7, 2015

URLValidator now validates the maximum length of a hostname in total
and the maximum length of all labels inside the hostname. The label
validation is done in the regular expression while the hostname length
check is implemented by introducing a new check in the validator's
call method. Please note that the additional call on urlsplit()
introduced there should not be a measurable performance overhead, as
urlsplit is called anyway in some of the code branches above and the
standard-library implementation uses an internal result cache.

@@ -83,9 +83,9 @@ class URLValidator(RegexValidator):
ipv6_re = r'\[[0-9a-f:\.]+\]' # (simple regex, validated later)

# Host patterns
hostname_re = r'[a-z' + ul + r'0-9](?:[a-z' + ul + r'0-9-]*[a-z' + ul + r'0-9])?'
Copy link
Member

Choose a reason for hiding this comment

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

I'd add a comment as done for EmailValidator: "# Max length for domain name labels is 63 characters per RFC 1034."

@timgraham timgraham changed the title Fixed #25637 -- URLValidator hostname length validation Fixed #25637 -- Added URLValidator hostname length validation. Nov 20, 2015
@raphaelm
Copy link
Contributor Author

I changed the comments with respect to your suggestions.

URLValidator now validates the maximum length of a hostname in total
and the maximum length of all labels inside the hostname. The label
validation is done in the regular expression while the hostname length
check is implemented by introducing a new check in the validator's
__call__ method. Please note that the additional call on urlsplit()
introduced there should not be a measurable performance overhead, as
urlsplit is called anyway in some of the code branches above and the
standard-library implementation uses an internal result cache.
@timgraham
Copy link
Member

merged in 82976e5, thanks!

@timgraham timgraham closed this Dec 8, 2015
@raphaelm raphaelm deleted the ticket_25637 branch December 9, 2015 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants