Skip to content

Commit

Permalink
Fix kwsplats in filter options
Browse files Browse the repository at this point in the history
Fixes #1790
  • Loading branch information
presidentbeef committed Oct 11, 2023
1 parent 9f6eb56 commit 422aec5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/brakeman/tracker/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ def before_filter_to_hash processor, args
filter[:methods] << a[1] if a.node_type == :lit
end

if args[-1].node_type == :hash
option = args[-1][1][1]
value = args[-1][2]
case value.node_type
when :array
filter[option] = value.sexp_body.map {|v| v[1] }
when :lit, :str
filter[option] = value[1]
else
Brakeman.debug "[Notice] Unknown before_filter value: #{option} => #{value}"
options = args.last

if hash? options
# Probably only one option,
# but this also avoids issues with kwsplats
hash_iterate(options) do |option, value|
case value.node_type
when :array
filter[option.value] = value.sexp_body.map {|v| v[1] }
when :lit, :str
filter[option.value] = value[1]
else
Brakeman.debug "[Notice] Unknown before_filter value: #{option} => #{value}"
end
end
else
filter[:all] = true
Expand Down
5 changes: 5 additions & 0 deletions test/apps/rails7/app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ def search_users
# Medium warning because it's probably an admin interface
User.ransack(params[:q])
end

# Test kwsplats in filter options
before_filter(**options) do |c|
x
end
end

0 comments on commit 422aec5

Please sign in to comment.