== Steps to Reproduce ==
{{{
#!python
>>> from django.core.validators import URLValidator
>>> validate = URLValidator()
>>> validate('http://example..com')
>>> validate('http://example...............com')
}}}
== Expected Result ==
A [https://docs.djangoproject.com/en/1.8/ref/exceptions/#validationerror
ValidationError] exception should be raised.
== Current Result ==
No exception is raised, and the URL is deemed valid.
== Reference ==
[https://tools.ietf.org/html/rfc2181#section-11 RFC 2181]:
The length of any one label is limited to between 1 and 63 octets. A
full domain name is limited to 255 octets (including the separators). The
zero length full name is defined as representing the root of the DNS
tree, and is typically written and displayed as ".".
--
Ticket URL: <https://code.djangoproject.com/ticket/25620>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Here are the relevant code part from URLValidator (this is from the master
branch)
{{{
hostname_re = r'[a-z' + ul + r'0-9](?:[a-z' + ul + r'0-9-]*[a-z' + ul +
r'0-9])?'
domain_re = r'(?:\.(?!-)[a-z' + ul + r'0-9-]*(?<!-))*'
tld_re = r'\.(?:[a-z' + ul + r']{2,}|xn--[a-z0-9]+)\.?'
host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)'
}}}
The culprit is domain_re which allows multiple dots due to '*' on [a-z0-9]
part. Changing * to + should solve the problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:2>
* Attachment "0001-Fixed-25620-Changed-to-in-domain-name-regex.patch"
added.
* has_patch: 0 => 1
Comment:
Could you submit the patch as a pull request?
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:3>
Comment (by DheerendraRathor):
Recently I've also noted that scheme regex is `r'^(?:[a-z0-9\.\-]*)://'`
but it should have been `r'^(?:[a-z0-9\.\-\+]+)://'` according to
[https://tools.ietf.org/html/rfc1738#section-2.1 rfc1738]. I'll update my
PR soon.
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:4>
* cc: dheeru.rathor14@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:5>
Comment (by DheerendraRathor):
Also current regex are not handling label limit of 63 characters and total
limit of 253 characters. Should I modify regex to handle them as well?
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:6>
Comment (by timgraham):
It's probably better to handle each issue separately. Otherwise, it's
difficult to determine which change matches which test.
Making the regex more complex must be done very carefully to avoid issues
like 17d3a6d8044752f482453f5906026eaf12c39e8e.
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:7>
Comment (by DheerendraRathor):
Cool, then I'll modify regex for domain name and scheme. For length
validation I'll open another ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:8>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"96fe90f5356971e0e51a0bc41e045dde600d7521" 96fe90f]:
{{{
#!CommitTicketReference repository=""
revision="96fe90f5356971e0e51a0bc41e045dde600d7521"
Fixed #25620 -- Made URLValidator prohibit URLs with consecutive dots in
the domain section.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"540de2f7972c6aa68fbf36c6a0da137d768f2067" 540de2f]:
{{{
#!CommitTicketReference repository=""
revision="540de2f7972c6aa68fbf36c6a0da137d768f2067"
[1.8.x] Fixed #25620 -- Made URLValidator prohibit URLs with consecutive
dots in the domain section.
Backport of 96fe90f5356971e0e51a0bc41e045dde600d7521 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:11>
Comment (by Tim Graham <timograham@…>):
In [changeset:"6bb9f51ab8e3cc56b05238ea012763ba775ab896" 6bb9f51]:
{{{
#!CommitTicketReference repository=""
revision="6bb9f51ab8e3cc56b05238ea012763ba775ab896"
[1.9.x] Fixed #25620 -- Made URLValidator prohibit URLs with consecutive
dots in the domain section.
Backport of 96fe90f5356971e0e51a0bc41e045dde600d7521 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25620#comment:10>