-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* check value of order filter To prevent parameters like: * `{"order":"captured_at desc) UNION ALL SELECT NULL,NULL,NULL#","locale":"en-US","device_id":"100171"}` * `{"order":"captured_at desc%' ORDER BY 1#","locale":"en-US","device_id":"100171"}` * specify locale in spec
- Loading branch information
Showing
7 changed files
with
28 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module HasOrderScope | ||
extend ActiveSupport::Concern | ||
|
||
VALID_SORT_ORDERS = %w(asc desc).freeze | ||
|
||
included do | ||
has_scope :order do |_controller, scope, value| | ||
_column_name, sort_order = value.split(' ', 2) | ||
|
||
sort_order = sort_order.to_s.strip.downcase || 'asc' | ||
if VALID_SORT_ORDERS.include?(sort_order) | ||
# TODO: Use `nulls_last` Arel method in Rails 6.1 | ||
scope.order("#{value} NULLS LAST") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters