#30731: simplify_regexp() doesn't replace trailing groups.
-----------------------------------+------------------------------------
     Reporter:  n2ygk              |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  contrib.admindocs  |                  Version:  master
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------
Changes (by felixxm):

 * version:  2.2 => master
 * stage:  Unreviewed => Accepted


Comment:

 Thanks for the ticket, trailing slash is not necessary regexp patterns
 could be also enclosed by `$`, by I agree that this could be easily fix
 by:

 {{{
 diff --git a/django/contrib/admindocs/utils.py
 b/django/contrib/admindocs/utils.py
 index 1ce4594501..db27f82deb 100644
 --- a/django/contrib/admindocs/utils.py
 +++ b/django/contrib/admindocs/utils.py
 @@ -167,12 +167,6 @@ def replace_named_groups(pattern):
          # Handle nested parentheses, e.g. '^(?P<a>(x|y))/b'.
          unmatched_open_brackets, prev_char = 1, None
          for idx, val in enumerate(pattern[end:]):
 -            # If brackets are balanced, the end of the string for the
 current
 -            # named capture group pattern has been reached.
 -            if unmatched_open_brackets == 0:
 -                group_pattern_and_name.append((pattern[start:end + idx],
 group_name))
 -                break
 -
              # Check for unescaped `(` and `)`. They mark the start and
 end of a
              # nested group.
              if val == '(' and prev_char != '\\':
 @@ -180,6 +174,11 @@ def replace_named_groups(pattern):
              elif val == ')' and prev_char != '\\':
                  unmatched_open_brackets -= 1
              prev_char = val
 +            # If brackets are balanced, the end of the string for the
 current
 +            # named capture group pattern has been reached.
 +            if unmatched_open_brackets == 0:
 +                group_pattern_and_name.append((pattern[start:end + idx +
 1], group_name))
 +                break

      # Replace the string for named capture groups with their group names.
      for group_pattern, group_name in group_pattern_and_name:
 }}}

 Similar change should be made in `replace_unnamed_groups()`. Please add
 testcases to
 `admin_docs.test_views.AdminDocViewFunctionsTests.test_simplify_regex`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30731#comment:2>
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/063.0867c3a2c4775d826dbe1c0976b4c68b%40djangoproject.com.

Reply via email to