Description
The error happens at
ransack/lib/ransack/nodes/value.rb
Line 83 in 9c66f49
The error happens when passing an array instead of a string/int to an _eq
predicate.
The implementation of this Value class doesn't handle errors as it should. It rescues things like Date.new(y, m, d) rescue nil
, yielding invalid search results eventually.
I would say it has to do exactly the opposite, all those rescue nil
should be gone, raising errors when invalid data is submitted. Those errors have to be handled in the application, not in the library.
A new error class can be introduced, e.g., Ransack::InvalidPropertyError
. This error can be raised when the submitted property doesn't match the expectations.
def cast_to_integer(val)
raise Ransack::InvalidPropertyError, "..." unless val.respond_to?(:to_i)
val.blank? ? nil : val.to_i
end
Date parsing should rely on RFC formats and raise otherwise, rather than trying some magick tricks, rescuing, and silently swallowing the errors, yielding invalid search results.