Integer fields accepts any value - even those which cannot be converted to a number

19 views
Skip to first unread message

brahmana

unread,
Feb 4, 2012, 6:12:27 AM2/4/12
to Mongoid
Hi,

An field of type Integer accepts any value provided. Mongoid attempts
to convert it to an integer or float but if it fails it just accepts
the object as it is.

Here is the relevant code :
https://github.com/mongoid/mongoid/blob/master/lib/mongoid/fields/internal/integer.rb#L36

Why is it implemented that way? Shouldn't it raise an argument error
or something similar like it does for the fields of type Array?

Relevant code here : https://github.com/mongoid/mongoid/blob/master/lib/mongoid/fields/internal/array.rb#L67

Or is it expected that the application has to sanitize the input?

I would expect mongoid to reject content that is not in accordance
with the type defined.

Regards,
Brahmana
@sribrahmana (http://www.twitter.com/sribrahmana)
Reply all
Reply to author
Forward
0 new messages