Opened 9 years ago

Closed 8 years ago

#26621 closed Bug (fixed)

simplify_regex handles named capture groups incorrectly

Reported by: Alex Rothberg Owned by: Ketan Bhatt
Component: contrib.admindocs Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

For example using a regex from Django Rest Framework docs:

>>> from django.contrib.admindocs.views import simplify_regex
>>> simplify_regex(r'^(?P<version>(v1|v2))/bookings/(?P<pk>[0-9]+)/$')
'/<version>)/bookings/<pk>/'

The closing parenthesis in the output is unexpected.

Escaping the / does not seem to help.

Change History (6)

comment:1 by Tim Graham, 8 years ago

Component: Uncategorizedcontrib.admindocs
Description: modified (diff)
Summary: simplify_regex having problems with named capture groupssimplify_regex handles named capture groups incorrectly
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 by Ketan Bhatt, 8 years ago

Owner: changed from nobody to Ketan Bhatt
Status: newassigned

comment:3 by Ketan Bhatt, 8 years ago

@cancan101
If you change your regex to ^(?P<version>v1|v2)/bookings/(?P<pk>[0-9]+)/$ it will work as expected (both the regex and simplify_regex).

But yes, simplify_regex needs to be fixed.

comment:4 by Tim Graham <timograham@…>, 8 years ago

In 16a842b3:

Refs #26621 -- Added tests for admindocs.views.simplify_regex().

comment:5 by Tim Graham, 8 years ago

Has patch: set
Patch needs improvement: set

PR with comments for improvement.

comment:6 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In f0ef0c4:

Fixed #26621 -- Corrected simplify_regex()'s handling of named capture groups.

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