Skip to content

Commit 16e28a9

Browse files
committed
PHPC-408: Ensure object_to_bson() always creates a BSON document
1 parent 4bae8c5 commit 16e28a9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/bson.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
717717
return;
718718
}
719719
}
720+
721+
/* Even if we don't know how to encode the object, ensure that we at least
722+
* create an empty BSON document. */
723+
bson_append_document_begin(bson, key, key_len, &child);
724+
bson_append_document_end(bson, &child);
720725
}
721726
void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char *key, long key_len, int entry_type, zval *entry TSRMLS_DC)
722727
{

tests/bson/bson-utcdatetime-001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Test#1 { "0" : { "$date" : 1416445411987 } }
5151
string(37) "{ "0" : { "$date" : 1416445411987 } }"
5252
string(37) "{ "0" : { "$date" : 1416445411987 } }"
5353
bool(true)
54-
Test#2 { }
55-
string(3) "{ }"
56-
string(3) "{ }"
54+
Test#2 { "0" : { } }
55+
string(14) "{ "0" : { } }"
56+
string(14) "{ "0" : { } }"
5757
bool(false)
5858
===DONE===

0 commit comments

Comments
 (0)