RUBY-74 raise InvalidDocument for any unrecognized types
This commit is contained in:
parent
1b189336a6
commit
e013618a8f
@ -369,6 +369,9 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
|
||||
SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&obj_length, 4);
|
||||
break;
|
||||
}
|
||||
buffer_free(buffer);
|
||||
rb_raise(InvalidDocument, "Unsupported type for BSON (%d)", TYPE(value));
|
||||
break;
|
||||
}
|
||||
case T_DATA:
|
||||
{
|
||||
@ -421,7 +424,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
|
||||
default:
|
||||
{
|
||||
buffer_free(buffer);
|
||||
rb_raise(rb_eTypeError, "no c encoder for this type yet (%d)", TYPE(value));
|
||||
rb_raise(InvalidDocument, "Unsupported type for BSON (%d)", TYPE(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -554,7 +554,7 @@ class BSON_RUBY
|
||||
when Symbol
|
||||
SYMBOL
|
||||
else
|
||||
raise "Unknown type of object: #{o.class.name}"
|
||||
raise InvalidDocument, "Unknown type of object: #{o.class.name}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -335,4 +335,15 @@ class BSONTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_invalid_object
|
||||
o = Object.new
|
||||
assert_raise InvalidDocument do
|
||||
BSON.serialize({:foo => o})
|
||||
end
|
||||
|
||||
assert_raise InvalidDocument do
|
||||
BSON.serialize({:foo => Date.today})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user