JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Filter using Array as value fails

Open
#497 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug
Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

Using 0.6.0

Trying to use a filter like so:

?filter[users][]=1&filter[users][]=2

which Rails parses to {"filter"=>{"users"=>["1","2"]}}

This results in a crash, because the CSV parsing that happens in verify_filter is causing an exception to be thrown:

Internal Server Error: private method `gets' called for ["1"]:Array /usr/local/var/rbenv/versions/2.2.1/lib/ruby/2.2.0/csv.rb:1798:in `block in shift'
/usr/local/var/rbenv/versions/2.2.1/lib/ruby/2.2.0/csv.rb:1796:in `loop'
/usr/local/var/rbenv/versions/2.2.1/lib/ruby/2.2.0/csv.rb:1796:in `shift'
/usr/local/var/rbenv/versions/2.2.1/lib/ruby/2.2.0/csv.rb:1315:in `parse_line'
/usr/local/var/rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.5.5/lib/jsonapi/resource.rb:538:in `verify_filter'
/usr/local/var/rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.5.5/lib/jsonapi/resource.rb:526:in `block in verify_filters'
/usr/local/var/rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.5.5/lib/jsonapi/resource.rb:525:in `each'
/usr/local/var/rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.5.5/lib/jsonapi/resource.rb:525:in `verify_filters'
/usr/local/var/rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.5.5/lib/jsonapi/operation.rb:45:in `apply'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The stack trace points to jsonapi/resource.rb:538, in verify_filter, where CSV parsing receives the array value. Reproduce the request with filter[users][]=1 and filter[users][]=2, then trace verify_filters and verify_filter. Done means this array-valued filter no longer crashes and is handled as a valid filter.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.