Opened 2 years ago

Last modified 4 weeks ago

#28936 new Bug

simplify_regex should remove redundant escape sequences outside groups — at Version 1

Reported by: Cristi Vîjdea Owned by: nobody
Component: contrib.admindocs Version: 2.0
Severity: Normal Keywords: simplify_regex path
Cc: ChillarAnand Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description (last modified by Cristi Vîjdea)

django.contrib.admindocs.views.simplify_urls should clean up escapes found outside path parameters. Otherwise, broken URLs with backslashes can be generated and displayed.

This is readily apparent with Django 2's path(), which aggresively escapes everything outside a <parameter> specifier, resulting in a urlpattern with backslash-escaped forward slashes:

>>> simplify_regex(r"^(?P<sport_slug>\w+)/athletes/(?P<athlete_slug>\w+)/$")
>>> simplify_regex(r"^(?P<sport_slug>\w+)\/athletes\/(?P<athlete_slug>\w+)\/$")

The second example is what path() would generate in urlpatterns.

You can, for example, see this issue affecting django-rest-framework here.

Change History (1)

comment:1 Changed 2 years ago by Cristi Vîjdea

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top