#28936: simplify_regex should remove redundant escape sequences outside groups
-------------------------------------+-------------------------------------
Reporter: Cristi Vîjdea | Owner: Oliver
| Cleary
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 2.0
Severity: Normal | Resolution:
Keywords: simplify_regex path | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Comment (by Oliver Cleary):
I have a PR for this ticket, however I am not sure it really needs to be
fixed.
The referenced DRF ticket was resolved by changing the usage of the
simplify_regex function to match the usage by Django, which is to pass in
the paths route string directly, rather than using it's generated regex
pattern.
Additionally, the given example does not seem to be correct as path does
not escape forward slashes.
{{{
>>> path('<slug:sports_slug>/athletes/<slug:athletes_slug>/', lambda:
None).pattern.regex.pattern
'^(?P<sports_slug>[-a-zA-Z0-9_]+)/athletes/(?P<athletes_slug>[-a-zA-Z0-9_]+)/$'
}}}
Testing the example in the DRF ticket however does exhibit the issue:
{{{
>>> path('^api/token-auth/', lambda: None).pattern.regex.pattern
'^\\^api/token\\-auth/$'
>>> simplify_regex(r'^\^api/token\-auth/$')
'/\\api/token\\-auth/'
}}}
With the fix in the PR the special characters are unescaped, and the `^?$`
are only stripped if not escaped.
--
Ticket URL: <https://code.djangoproject.com/ticket/28936#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.7268b3e1c4c14dadb7ce4872f05d4053%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.