Description
BsonDocument.Parse() allows extra text after the first document, and ignores it. For example:
var jsontext = "{ foo: 'test'} ignored ignored {bar:'test'}";
|
Console.WriteLine(BsonDocument.Parse(jsontext));
|
// output {'foo': 'test'}
|
|
|
jsontext = "{ foo: 'test'} , {bar:'test'}";
|
Console.WriteLine(BsonDocument.Parse(jsontext));
|
// output {'foo': 'test'}
|
As observed, BsonDocument.Parse does not seem to complain that the second text is invalid, and ignored the rest.
Although if the first document is invalid, it will throw FormatException , for example :
jsontext = "{ foo: 'test2 ' ; bar: 'test'}"; // semi-colon instead of comma
|
Console.WriteLine(BsonDocument.Parse(jsontext));
|
Only the first full document is read/validated.