@@ -210,23 +210,28 @@ def check_include(resource_klass, include_parts)
210210 end
211211 end
212212
213- def parse_include_directives ( include )
214- return if include . nil?
213+ def parse_include_directives ( raw_include )
214+ return unless raw_include
215215
216216 unless JSONAPI . configuration . allow_include
217217 fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( [ :include ] )
218218 end
219219
220- included_resources = CSV . parse_line ( include )
221- return if included_resources . nil?
220+ included_resources = [ ]
221+ begin
222+ included_resources += CSV . parse_line ( raw_include )
223+ rescue CSV ::MalformedCSVError
224+ fail JSONAPI ::Exceptions ::InvalidInclude . new ( format_key ( @resource_klass . _type ) , raw_include )
225+ end
226+
227+ return if included_resources . empty?
222228
223- include = [ ]
224- included_resources . each do |included_resource |
229+ result = included_resources . map do |included_resource |
225230 check_include ( @resource_klass , included_resource . partition ( '.' ) )
226- include . push ( unformat_key ( included_resource ) . to_s )
231+ unformat_key ( included_resource ) . to_s
227232 end
228233
229- @include_directives = JSONAPI ::IncludeDirectives . new ( @resource_klass , include )
234+ @include_directives = JSONAPI ::IncludeDirectives . new ( @resource_klass , result )
230235 end
231236
232237 def parse_filters ( filters )
@@ -265,7 +270,15 @@ def parse_sort_criteria(sort_criteria)
265270 fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( [ :sort ] )
266271 end
267272
268- @sort_criteria = CSV . parse_line ( URI . unescape ( sort_criteria ) ) . collect do |sort |
273+ sorts = [ ]
274+ begin
275+ raw = URI . unescape ( sort_criteria )
276+ sorts += CSV . parse_line ( raw )
277+ rescue CSV ::MalformedCSVError
278+ fail JSONAPI ::Exceptions ::InvalidSortCriteria . new ( format_key ( @resource_klass . _type ) , raw )
279+ end
280+
281+ @sort_criteria = sorts . collect do |sort |
269282 if sort . start_with? ( '-' )
270283 sort_criteria = { field : unformat_key ( sort [ 1 ..-1 ] ) . to_s }
271284 sort_criteria [ :direction ] = :desc
0 commit comments