Skip to content

Commit 005f475

Browse files
committed
Don't consume .json style suffixes with routers.
When trailing slash is false, the lookup regex should not consume '.' characters. Fixes #1057.
1 parent f54fc3a commit 005f475

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rest_framework/routers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ def get_lookup_regex(self, viewset):
189189
Given a viewset, return the portion of URL regex that is used
190190
to match against a single instance.
191191
"""
192-
base_regex = '(?P<{lookup_field}>[^/]+)'
192+
if self.trailing_slash:
193+
base_regex = '(?P<{lookup_field}>[^/]+)'
194+
else:
195+
# Don't consume `.json` style suffixes
196+
base_regex = '(?P<{lookup_field}>[^/.]+)'
193197
lookup_field = getattr(viewset, 'lookup_field', 'pk')
194198
return base_regex.format(lookup_field=lookup_field)
195199

0 commit comments

Comments
 (0)