[1.11.x] Fixed #27781 -- Made simplify_regex() remove outstanding '?' characters.

Regression in f0ef0c49e9.

Backport of c37ec5a659 from master
This commit is contained in:
Mariusz Felisiak 2017-01-27 00:36:34 +01:00 committed by Tim Graham
parent 7dda48bf18
commit 092f09fcc1
2 changed files with 2 additions and 1 deletions

View File

@ -436,7 +436,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

View File

@ -340,6 +340,7 @@ class AdminDocViewFunctionsTests(SimpleTestCase):
(r'^(?P<a>(x|y))/b/(?P<c>\w+)$', '/<a>/b/<c>'),
(r'^(?P<a>(x|y))/b/(?P<c>\w+)ab', '/<a>/b/<c>ab'),
(r'^(?P<a>(x|y)(\(|\)))/b/(?P<c>\w+)ab', '/<a>/b/<c>ab'),
(r'^a/?$', '/a/'),
)
for pattern, output in tests:
self.assertEqual(simplify_regex(pattern), output)