Contrib: fix required params implementation
When required_params is called in such a way that it expects a key in the params to be a hash, it fails with error undefined method has_key? when it is not indeed a hash in the params in a request. Now, it's been ensured that the key can respond to has_key? before has_key? is called on it. So, required_params :p1, :p2 => [:p3] now works properly even if :p2 turns out not to point to a hash, e. g. if the params hash is { p1: 2, p2: 3 } it will properly halt with status 400.
This commit is contained in:
parent
df87572b0d
commit
55858e6c4d
|
@ -60,7 +60,7 @@ module Sinatra
|
|||
elsif key.is_a?(Array)
|
||||
_required_params(p, *key)
|
||||
else
|
||||
halt 400 unless p.has_key?(key.to_s)
|
||||
halt 400 unless p && p.respond_to?(:has_key?) && p.has_key?(key.to_s)
|
||||
end
|
||||
end
|
||||
true
|
||||
|
|
Loading…
Reference in New Issue