Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 589740e

Browse files
committed
HHVM-183: toJSON() should throw if bson_as_json() fails
This passes tests for PHPC-613.
1 parent d6b7aa4 commit 589740e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/MongoDB/BSON/functions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ Variant HHVM_FUNCTION(MongoDBBsonToJson, const String &data)
9999

100100
str = bson_as_json(b, &str_len);
101101

102+
if (!str) {
103+
bson_reader_destroy(reader);
104+
throw MongoDriver::Utils::throwUnexpectedValueException("Could not convert BSON document to a JSON string");
105+
}
106+
102107
s = String(str_len, ReserveString);
103108
data_s = (unsigned char*) s.bufferSlice().data();
104109
memcpy(data_s, str, str_len);

0 commit comments

Comments
 (0)