From 486a8f82b2bb91c8a4c06c7acc9671650be5ac9f Mon Sep 17 00:00:00 2001 From: David Sutherland Date: Mon, 17 Aug 2015 10:29:09 +1000 Subject: [PATCH] Allow format suffixes after trailing slash --- rest_framework/urlpatterns.py | 5 ++++- tests/test_urlpatterns.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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), ]