[Django] #22589: url reverse should encode forward slashes

6 views
Skip to first unread message

Django

unread,
May 6, 2014, 6:31:29 PM5/6/14
to django-...@googlegroups.com
#22589: url reverse should encode forward slashes
-------------------------------+--------------------
Reporter: denilsonsa | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I have essentially the same issue as this guy:
http://stackoverflow.com/questions/4241484/use-djangos-url-template-tag-
with-special-characters

{{{
# In urls.py:
url(r'^something/(?P<title>[^/]*)/something/else$', views.something,
name='something'),

# In a template:
<a href="{% url something page.title %}">Some link</a>
}}}

Here, `page.title` is a completely free-form string that might contain any
characters, including forward slashes. I want to encode it completely. The
current url `reverse()` code will quote any parameters using Django's
`urlquote`, which will call Python's `quote`, which will encode all
special characters, except the slash (and `_.-`).

https://github.com/django/django/blob/91afc00513bd2fa6302ea2be35e1f842cbd5fd38/django/core/urlresolvers.py#L459

There is no hook or option to make url reverse encode the slash while
building the URL. We can't pre-encode the slash either, as it will lead to
double-encoding the slashes (requiring an extra decoding step inside the
view). So, there is no straightforward way to build a URL while encoding
the slashes from args.

My suggestion is to change the behavior of url reverse to also encode
forward slashes. Or, at least, give some flexibility when encoding the
URL.

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

Django

unread,
May 12, 2014, 8:56:28 AM5/12/14
to django-...@googlegroups.com
#22589: url reverse should encode forward slashes
-------------------------------+--------------------------------------
Reporter: denilsonsa | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.6
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

This is complicated, but I believe it's covered in #22223.

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

Reply all
Reply to author
Forward
0 new messages