Opened 5 years ago

Closed 5 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


I have essentially the same issue as this guy:

# In
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 _.-).

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 Changed 5 years ago by Tim Graham

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