Opened 11 years ago

Closed 10 years ago

#22589 closed Uncategorized (duplicate)

url reverse should encode forward slashes

Reported by: Denilson Figueiredo de Sá Owned by: nobody
Component: Uncategorized Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (1)

comment:1 by Tim Graham, 10 years ago

Resolution: duplicate
Status: newclosed

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

Note: See TracTickets for help on using tickets.
Back to Top