diff --git a/rest_framework/urlpatterns.py b/rest_framework/urlpatterns.py index 5347b3bc1..5666a9bdb 100644 --- a/rest_framework/urlpatterns.py +++ b/rest_framework/urlpatterns.py @@ -23,7 +23,10 @@ def apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required): else: # Regular URL pattern - regex = urlpattern.regex.pattern.rstrip('$').rstrip('/') + suffix_pattern + regex = urlpattern.regex.pattern.rstrip('$') + if regex[-1:] == '/': + regex += '?' + regex += suffix_pattern view = urlpattern._callback or urlpattern._callback_str kwargs = urlpattern.default_args name = urlpattern.name diff --git a/tests/test_urlpatterns.py b/tests/test_urlpatterns.py index 78d37c1a8..e0ca667ee 100644 --- a/tests/test_urlpatterns.py +++ b/tests/test_urlpatterns.py @@ -47,7 +47,7 @@ class FormatSuffixTests(TestCase): test_paths = [ (URLTestPath('/test.api', (), {'format': 'api'}), True), - (URLTestPath('/test/.api', (), {'format': 'api'}), False), + (URLTestPath('/test/.api', (), {'format': 'api'}), True), (URLTestPath('/test.api/', (), {'format': 'api'}), True), ]