Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [#2693](https://github.com/ruby-grape/grape/pull/2693): Introduce `Grape::Exceptions::ErrorResponse` value object to replace the implicit-schema Hash thrown via `throw` - [@ericproulx](https://github.com/ericproulx).
* [#2701](https://github.com/ruby-grape/grape/pull/2701): Replace `.tap` usages in `lib/` with explicit local variables - [@ericproulx](https://github.com/ericproulx).
* [#2704](https://github.com/ruby-grape/grape/pull/2704): Add `Grape::Endpoint#logger` so the API's configured logger is reachable inside route handlers, filters, and `rescue_from` blocks without a helper - [@ericproulx](https://github.com/ericproulx).
* [#2707](https://github.com/ruby-grape/grape/pull/2707): Tighten six guard conditions in `lib/` via De Morgan and `blank?`/`present?`/`include?` rewrites; no behaviour change - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
5 changes: 4 additions & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ class API
Helpers = Grape::DSL::Helpers::BaseHelper

class Boolean
VALUES = [true, false].freeze
private_constant :VALUES

def self.build(val)
return nil if val != true && val != false
return nil unless VALUES.include?(val)

new
end
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def route(methods, paths = ['/'], route_options = {}, &)
endpoint_description = inheritable_setting.route[:description]
all_route_options = { params: endpoint_params }
all_route_options.deep_merge!(endpoint_description) if endpoint_description
all_route_options.deep_merge!(route_options) if route_options&.any?
all_route_options.deep_merge!(route_options) if route_options.present?

new_endpoint = Grape::Endpoint.new(
inheritable_setting,
Expand Down
5 changes: 3 additions & 2 deletions lib/grape/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ def cookies
def make_params
params = @params_builder.call(rack_params)
routing_args = env[Grape::Env::GRAPE_ROUTING_ARGS]
return params unless routing_args&.any? { |k, _| k != :version && k != :route_info }
filtered = routing_args&.except(:version, :route_info)
return params if filtered.blank?

params.deep_merge!(routing_args.except(:version, :route_info))
params.deep_merge!(filtered)
rescue *Grape::RACK_ERRORS
raise Grape::Exceptions::RequestError
end
Expand Down
4 changes: 2 additions & 2 deletions lib/grape/validations/params_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ def guess_coerce_type(coerce_type, *values_list)
end

def check_incompatible_option_values(default, values, except_values)
return unless default && !default.is_a?(Proc)
return if default.nil? || default.is_a?(Proc)

raise Grape::Exceptions::IncompatibleOptionValues.new(:default, default, :values, values) if values && !values.is_a?(Proc) && !Array(default).all? { |def_val| values.include?(def_val) }
raise Grape::Exceptions::IncompatibleOptionValues.new(:default, default, :values, values) if values && !values.is_a?(Proc) && Array(default).any? { |def_val| !values.include?(def_val) }

return unless except_values && !except_values.is_a?(Proc) && Array(default).any? { |def_val| except_values.include?(def_val) }

Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/validators/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def option_value
end

def scrub(value)
return value unless value.respond_to?(:valid_encoding?) && !value.valid_encoding?
return value if !value.respond_to?(:valid_encoding?) || value.valid_encoding?

value.scrub
end
Expand Down
Loading