[Django] #29667: path converters don't handle spaces well.

21 views
Skip to first unread message

Django

unread,
Aug 14, 2018, 3:36:53 AM8/14/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn | Owner: nobody
Knight |
Type: Bug | Status: new
Component: Core | Version: master
(URLs) | Keywords: converters path
Severity: Normal | _route_to_regex
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
This came up for someone on IRC last week, but I can't see that they
raised a ticket about it.

Correct:
{{{
>>> from django.urls.resolvers import _route_to_regex
>>> _route_to_regex("<uuid:test>")
('^(?P<test>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})',
{'test': <django.urls.converters.UUIDConverter at 0x1055e8c88>})
}}}

Also working correctly:
{{{
>>> from django.urls.resolvers import _route_to_regex
>>> _route_to_regex("<uuid:2>")
ImproperlyConfigured: URL route '<uuid:2>' uses parameter name '2' which
isn't a valid Python identifier.
}}}

however, constructing a valid **looking** converter reference apparently
hits neither the happy nor the unhappy path, and also I presume passes any
system checks in place that might otherwise warn about the sensitivity:
{{{
>>> from django.urls.resolvers import _route_to_regex
>>> _route_to_regex("<uuid: test>") # note the preceeding space
('^\\<uuid\\:\\ test\\>', {})
}}}
- the regex is invalid
- the kwargs dictionary is (sort of rightly) empty.
- the same is true with "test " and "te st"

Unless I'm misunderstanding the code therein, "test ", " test" and "te st"
should all be hitting the invalid identifier part, and personally I feel
like leading/trailing spaces at least could just be sanitised (stripped)
as they're almost certainly accidental or for display purposes.

Tested in a shell against master @
7eb556a6c2b2ac9313158f8b812eebea02a43f20.

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

Django

unread,
Aug 14, 2018, 4:40:44 AM8/14/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

Thanks for the report Keryn. This looks reasonable.

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

Django

unread,
Aug 14, 2018, 10:11:41 AM8/14/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Jeff
Type: Bug | Status: assigned

Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jeff):

* owner: nobody => Jeff
* status: new => assigned


Comment:

happy to look into this.

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

Django

unread,
Aug 26, 2018, 11:37:21 AM8/26/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Jeff
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tom Forbes):

I ran into this recently and ended up diagnosing the failure so I really
hope you do not mind me jumping in and offering a PR Jeff. The path
parameter regex was just a bit too strict about parsing spaces, and so
ended up ignoring the pattern entirely

PR: https://github.com/django/django/pull/10336

I believe this fixes the issue but I'm not sure how much we want to
document this. Should we raise a check failure?

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

Django

unread,
Aug 26, 2018, 11:59:20 AM8/26/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Jeff
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tom Forbes):

* cc: Tom Forbes (added)


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

Django

unread,
Aug 26, 2018, 7:32:15 PM8/26/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Jeff
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I think it would be be best to prohibit whitespace.

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

Django

unread,
Aug 30, 2018, 3:53:42 PM8/30/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Jeff
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Adam (Chainz) Johnson):

I agree, prohibiting whitespace would be best, it would avoid 'dialects'
of urlconfs appearing and the potential for future problems.

--
Ticket URL: <https://code.djangoproject.com/ticket/29667#comment:6>

Django

unread,
Sep 16, 2018, 3:34:44 AM9/16/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Jeff
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Vishvajit Pathak):

Tim, Adam,
So do we want to raise `ImproperlyConfigured` when whitespace is used ?

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

Django

unread,
Oct 3, 2018, 2:40:33 AM10/3/18
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Jeff
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Vishvajit Pathak):

* cc: Vishvajit Pathak (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29667#comment:8>

Django

unread,
Aug 19, 2019, 11:55:02 AM8/19/19
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Hasan
| Ramezani

Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* owner: Jeff => Hasan Ramezani
* has_patch: 0 => 1


Comment:

PR [https://github.com/django/django/pull/11688]

--
Ticket URL: <https://code.djangoproject.com/ticket/29667#comment:9>

Django

unread,
Aug 20, 2019, 5:16:00 AM8/20/19
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Accepted
_route_to_regex |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


Comment:

Patch looks good: just a few adjustments and ready to go. (I'll mark RFC
to keep it on my rader: I assume Hasan will turn them around quickly, as
ever 🙂) Thanks Hasan!

--
Ticket URL: <https://code.djangoproject.com/ticket/29667#comment:10>

Django

unread,
Aug 20, 2019, 5:16:19 AM8/20/19
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: converters path | Triage Stage: Ready for
_route_to_regex | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29667#comment:11>

Django

unread,
Aug 20, 2019, 5:53:48 AM8/20/19
to django-...@googlegroups.com
#29667: path converters don't handle spaces well.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Hasan
| Ramezani
Type: Bug | Status: closed

Component: Core (URLs) | Version: master
Severity: Normal | Resolution: fixed

Keywords: converters path | Triage Stage: Ready for
_route_to_regex | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton.gibson@…>):

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


Comment:

In [changeset:"22394bd3a18a7d9a8957a0b431f8ae4e5ca03a8c" 22394bd3]:
{{{
#!CommitTicketReference repository=""
revision="22394bd3a18a7d9a8957a0b431f8ae4e5ca03a8c"
Fixed #29667 -- Prohibited whitespaces in path() URLs.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29667#comment:12>

Reply all
Reply to author
Forward
0 new messages