File tree Expand file tree Collapse file tree 2 files changed +11
-16
lines changed
rest_framework_json_api/filters Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -314,17 +314,6 @@ def test_filter_missing_right_bracket(self):
314
314
self .assertEqual (dja_response ['errors' ][0 ]['detail' ],
315
315
"invalid filter: filter[headline" )
316
316
317
- def test_filter_incorrect_brackets (self ):
318
- """
319
- test for filter with incorrect brackets
320
- """
321
- response = self .client .get (self .url , data = {'filter{headline}' : 'foobar' })
322
- self .assertEqual (response .status_code , 400 ,
323
- msg = response .content .decode ("utf-8" ))
324
- dja_response = response .json ()
325
- self .assertEqual (dja_response ['errors' ][0 ]['detail' ],
326
- "invalid filter: filter{headline}" )
327
-
328
317
def test_filter_missing_rvalue (self ):
329
318
"""
330
319
test for filter with missing value to test against
Original file line number Diff line number Diff line change @@ -57,13 +57,19 @@ class JSONAPIDjangoFilter(DjangoFilterBackend):
57
57
`filter[<something>]` to comply with the jsonapi spec requirement to use the filter
58
58
keyword. The default is "search" unless overriden but it's used here just to make sure
59
59
we don't complain about it being an invalid filter.
60
-
61
- TODO: find a better way to deal with search_param.
62
60
"""
61
+ # TODO: find a better way to deal with search_param.
63
62
search_param = api_settings .SEARCH_PARAM
64
- # since 'filter' passes query parameter validation but is still invalid,
65
- # make this regex check for it but not set `filter` regex group.
66
- filter_regex = re .compile (r'^filter(?P<ldelim>\W*)(?P<assoc>[\w._]*)(?P<rdelim>\W*$)' )
63
+
64
+ # Make this regex check for 'filter' as well as 'filter[...]'
65
+ # Leave other incorrect usages of 'filter' to JSONAPIQueryValidationFilter.
66
+ # See http://jsonapi.org/format/#document-member-names for allowed characters
67
+ # and http://jsonapi.org/format/#document-member-names-reserved-characters for reserved
68
+ # characters (for use in paths, lists or as delimiters).
69
+ # regex `\w` matches [a-zA-Z0-9_].
70
+ # TODO: U+0080 and above allowed but not recommended. Leave them out for now. Fix later?
71
+ # Also, ' ' (space) is allowed within a member name but not recommended.
72
+ filter_regex = re .compile (r'^filter(?P<ldelim>\[?)(?P<assoc>[\w\.\-]*)(?P<rdelim>\]?$)' )
67
73
68
74
def validate_filter (self , keys , filterset_class ):
69
75
for k in keys :
You can’t perform that action at this time.
0 commit comments