Fixed BSON serialization bug: was modifying objects with ids.
This commit is contained in:
parent
128b11e92c
commit
dc3ef378d3
|
@ -80,9 +80,9 @@ class BSON
|
||||||
@buf.put_int(0)
|
@buf.put_int(0)
|
||||||
|
|
||||||
# Write key/value pairs. Always write _id first if it exists.
|
# Write key/value pairs. Always write _id first if it exists.
|
||||||
oid = obj.delete('_id') || obj.delete(:_id)
|
oid = obj['_id'] || obj[:_id]
|
||||||
serialize_key_value('_id', oid) if oid
|
serialize_key_value('_id', oid) if oid
|
||||||
obj.each {|k, v| serialize_key_value(k, v) }
|
obj.each {|k, v| serialize_key_value(k, v) unless k == '_id' || k == :_id }
|
||||||
|
|
||||||
serialize_eoo_element(@buf)
|
serialize_eoo_element(@buf)
|
||||||
@buf.put_int(@buf.size, 0)
|
@buf.put_int(@buf.size, 0)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'mongo'
|
s.name = 'mongo'
|
||||||
s.version = '0.3.0'
|
s.version = '0.3.1'
|
||||||
s.platform = Gem::Platform::RUBY
|
s.platform = Gem::Platform::RUBY
|
||||||
s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
|
s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
|
||||||
s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
|
s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
|
||||||
|
|
|
@ -155,4 +155,18 @@ class BSONTest < Test::Unit::TestCase
|
||||||
assert_equal '_id', roundtrip.keys.first
|
assert_equal '_id', roundtrip.keys.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_do_not_change_original_object
|
||||||
|
val = OrderedHash.new
|
||||||
|
val['not_id'] = 1
|
||||||
|
val['_id'] = 2
|
||||||
|
assert val.keys.include?('_id')
|
||||||
|
@b.serialize(val)
|
||||||
|
assert val.keys.include?('_id')
|
||||||
|
|
||||||
|
val = {'a' => 'foo', 'b' => 'bar', :_id => 42, 'z' => 'hello'}
|
||||||
|
assert val.keys.include?(:_id)
|
||||||
|
@b.serialize(val)
|
||||||
|
assert val.keys.include?(:_id)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue