#28936: simplify_regex should remove redundant escape sequences outside groups
-------------------------------------+-------------------------------------
     Reporter:  Cristi Vîjdea        |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.admindocs    |                  Version:  2.0
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  simplify_regex path  |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  1
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Thanks for the patch Oliver.

 > ... I am not sure it really needs to be fixed.

 I think this is right.

 As with the DRF issue, calling `str()` on `path.pattern` before passing to
 `simplify_regex()` is the correct usage, and
 
[https://github.com/django/django/blob/5ea1621c724e765c9a642a1b3b6e83419fda920b/django/contrib/admindocs/views.py#L389
 it is what `admindocs` does].

 Here using [https://github.com/encode/django-rest-
 framework/issues/5675#issue-282663045 the original example from the DRF
 issue]:

 {{{
 >>> from django.urls import path
 >>> from django.contrib.admindocs.views import simplify_regex
 >>> p = path('^api/token-auth/', lambda: None)  # Not sure about the `^`,
 but either way…
 >>> p.pattern
 <django.urls.resolvers.RoutePattern object at 0x10acd49d0>
 >>> p.pattern.regex.pattern
 '^\\^api/token\\-auth/$'
 >>> simplify_regex(p.pattern.regex.pattern)  # Wrong usage.
 '/\\api/token\\-auth/'
 >>> str(p.pattern)
 '^api/token-auth/'
 >>> simplify_regex(str(p.pattern))  # Correct usage.
 '/api/token-auth/'
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28936#comment:8>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.7b3a9a0f5265f2c5ce4d46ffbfd160cb%40djangoproject.com.

Reply via email to