Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33499 closed New feature (wontfix)

{% url '...' test=a %} fails when "a" contains a forward slash

Reported by: Antônio Martos Harres Owned by: nobody
Component: Core (URLs) Version: 3.2
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

When using {% url %}, if the dictionary passed to the second parameter is dinamically generated on the template and contains a slash, it fails with a "No reverse match" error, to reproduce, do the following:

In the template (html file):
{% url 'post_list' category=category %}

In the urls.py file:
urlpatterns = [ path('posts/<str:category>/', post_list, name='post_list'), ]

Now if you pass a {"category": "something/"} to the render functionality, it will fail with a no reverse match, this is because, in the views, the matcher for anything passed in the urls cannot contain a slash, for instance, <str:category> will not match if it contains a slash

To solve this issue, I recommend enconding the slash as %2F

Change History (2)

comment:1 by Carlton Gibson, 3 years ago

Resolution: wontfix
Status: newclosed

Hi Antônio...

if you pass a {"category": "something/"}

I think we'd just put this down to wrong usage no? The URL path pattern provides the trailing /, so passing it as part of the parameter is not intended. (If you really want something%2F, I think you need to pass that yourself.)

Thanks.

comment:2 by Carlton Gibson, 3 years ago

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