Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bson/_cbsonmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,12 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,

value = elements_to_dict(self, buffer + *position,
size, options);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove this blank line

if (options->is_raw_bson) {
*position += size;
break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest moving this below the !value error check.


if (!value) {
goto invalid;
}
Expand Down
10 changes: 9 additions & 1 deletion test/test_raw_bson.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from test import client_context, unittest
from test.test_client import IntegrationTest

from bson import Code, decode, encode
from bson import Code, DBRef, decode, encode
from bson.binary import JAVA_LEGACY, Binary, UuidRepresentation
from bson.codec_options import CodecOptions
from bson.errors import InvalidBSON
Expand Down Expand Up @@ -205,6 +205,14 @@ def test_contains_code_with_scope(self):
self.assertEqual(decode(encode(doc)), {"value": Code("x=1", {})})
self.assertEqual(doc["value"].scope, RawBSONDocument(encode({})))

def test_contains_dbref(self):
doc = RawBSONDocument(encode({"value": DBRef("test", "id")}))
raw = {"$ref": "test", "$id": "id"}
raw_encoded = encode(decode(encode(raw)))

self.assertEqual(decode(encode(doc)), {"value": DBRef("test", "id")})
self.assertEqual(doc["value"].raw, raw_encoded)


if __name__ == "__main__":
unittest.main()