[Django] #25595: Invalid regexp in URLValidator can't handle file:// schemes

33 views
Skip to first unread message

Django

unread,
Oct 22, 2015, 9:08:12 AM10/22/15
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
-------------------------------+--------------------
Reporter: marcinn | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Regexp does not allow to use `file` scheme in URLValidator.

== Steps to reproduce ==

{{{
from django.core.validators import URLValidator
URLValidator(schemes=['file'])('file:///tmp/somefile')
}}}

== Expected result ==

No exception should be raised.

== Current result ==

{{{
ValidationError: [u'Enter a valid URL.']
}}}

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

Django

unread,
Oct 22, 2015, 12:59:50 PM10/22/15
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
------------------------------+------------------------------------

Reporter: marcinn | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* component: Uncategorized => Core (Other)
* needs_tests: => 0
* needs_docs: => 0


Comment:

Can this be fixed without special casing the file scheme in the
validation?

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

Django

unread,
Oct 22, 2015, 5:25:58 PM10/22/15
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
------------------------------+------------------------------------

Reporter: marcinn | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by claudep):

It's `URLValidator` not `URIValidator`, I think you might need your own
custom validator for this. The current regex is already bloated, I'm not
sure we should continue to complexify it...

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

Django

unread,
Oct 22, 2015, 6:53:14 PM10/22/15
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
------------------------------+------------------------------------

Reporter: marcinn | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by timgraham):

I had a similar skepticism. If we don't make a change, then let's clarify
the documentation to prevent further tickets about this.

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

Django

unread,
Nov 11, 2015, 2:50:38 PM11/11/15
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
------------------------------+------------------------------------

Reporter: marcinn | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by codingjoe):

I thinks this is both a documentation and code problem. The `URLValidator`
should raise a value error, if a unsupported schema is set. In the
documentation it should be explained with RFC 1738 schemas are supported.
Currently one gets the impression that all are.

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

Django

unread,
Nov 11, 2015, 2:53:45 PM11/11/15
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
------------------------------+------------------------------------

Reporter: marcinn | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by codingjoe):

Interestingly enough, if you include the optional host parameter in
RFC1738 it works: `file://localhost/tmp/file/name`

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

Django

unread,
Mar 9, 2024, 12:20:23 AM3/9/24
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
------------------------------+-----------------------------------------
Reporter: Marcin Nowak | Owner: Adam Zapletal
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+-----------------------------------------
Changes (by Adam Zapletal):

* cc: Adam Zapletal (added)
* has_patch: 0 => 1
* owner: nobody => Adam Zapletal
* status: new => assigned

Comment:

I opened a PR adding a warning about this to the documentation. I'm happy
to handle it in a different way if that'd be better.

For what it's worth, if someone out there wants to validate local file
URIs, you could start with something like this:

{{{#!python
@deconstructible
class CustomURLValidator(URLValidator):
def __init__(self, **kwargs):
super().__init__(**kwargs)

self.schemes.append('file')

def __call__(self, value):
if value.startswith('file:///'):
value = value.replace('file:///', 'file://localhost/')

return super().__call__(value)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25595#comment:6>

Django

unread,
Mar 11, 2024, 3:18:28 AM3/11/24
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
-------------------------------------+-------------------------------------
Reporter: Marcin Nowak | Owner: Adam
| Zapletal
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | 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 Mariusz Felisiak):

* stage: Accepted => Ready for checkin

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

Django

unread,
Mar 11, 2024, 4:24:26 AM3/11/24
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
-------------------------------------+-------------------------------------
Reporter: Marcin Nowak | Owner: Adam
| Zapletal
Type: Bug | Status: closed
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution: fixed
Keywords: | 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 Mariusz Felisiak <felisiak.mariusz@…>):

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

Comment:

In [changeset:"7326513a8f5d4d4e0aeec28540f9451b939b1dda" 7326513a]:
{{{#!CommitTicketReference repository=""
revision="7326513a8f5d4d4e0aeec28540f9451b939b1dda"
Fixed #25595 -- Doc'd that URLValidator rejects file:// URIs without a
host.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25595#comment:8>

Django

unread,
Mar 11, 2024, 4:25:11 AM3/11/24
to django-...@googlegroups.com
#25595: Invalid regexp in URLValidator can't handle file:// schemes
-------------------------------------+-------------------------------------
Reporter: Marcin Nowak | Owner: Adam
| Zapletal
Type: Bug | Status: closed
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution: fixed
Keywords: | 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 Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"710ca576816fe90c15a7e62f95074ff0bbd77f0e" 710ca576]:
{{{#!CommitTicketReference repository=""
revision="710ca576816fe90c15a7e62f95074ff0bbd77f0e"
[5.0.x] Fixed #25595 -- Doc'd that URLValidator rejects file:// URIs
without a host.

Backport of 7326513a8f5d4d4e0aeec28540f9451b939b1dda from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25595#comment:9>
Reply all
Reply to author
Forward
0 new messages