From c37ec5a6595f963a04fae1b17858225c2b3d08c4 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 27 Jan 2017 00:36:34 +0100 Subject: [PATCH] Fixed #27781 -- Made simplify_regex() remove outstanding '?' characters. Regression in f0ef0c49e9284f262fbc63e8a497699ca4a248fe. --- django/contrib/admindocs/views.py | 2 +- tests/admin_docs/test_views.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index a3a70b095c..0e7f3382ca 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -430,7 +430,7 @@ def simplify_regex(pattern): pattern = replace_named_groups(pattern) pattern = replace_unnamed_groups(pattern) # clean up any outstanding regex-y characters. - pattern = pattern.replace('^', '').replace('$', '') + pattern = pattern.replace('^', '').replace('$', '').replace('?', '') if not pattern.startswith('/'): pattern = '/' + pattern return pattern diff --git a/tests/admin_docs/test_views.py b/tests/admin_docs/test_views.py index 34f6af6cdc..0915e01dc4 100644 --- a/tests/admin_docs/test_views.py +++ b/tests/admin_docs/test_views.py @@ -336,6 +336,7 @@ class AdminDocViewFunctionsTests(SimpleTestCase): (r'^(?P(x|y))/b/(?P\w+)$', '//b/'), (r'^(?P(x|y))/b/(?P\w+)ab', '//b/ab'), (r'^(?P(x|y)(\(|\)))/b/(?P\w+)ab', '//b/ab'), + (r'^a/?$', '/a/'), ) for pattern, output in tests: self.assertEqual(simplify_regex(pattern), output)