[CSHARP-1676] BsonDocument.Parse and multiple JSON values Created: 23/May/16  Updated: 19/Apr/18  Resolved: 25/May/16

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.2.4
Fix Version/s: 2.3

Type: Task Priority: Minor - P4
Reporter: Wan Bachtiar Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change

 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.



 Comments   
Comment by Githook User [ 25/May/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1676: BsonDocument.Parse should throw a FormatException if string contains extra characters.
Branch: v2.2.x
https://github.com/mongodb/mongo-csharp-driver/commit/419686829f5de9d98b2167c1f028a5599ac8b81f

Comment by Githook User [ 25/May/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1676: BsonDocument.Parse should throw a FormatException if string contains extra characters.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/d0aa4ae05636726da2f5d64f590ddbed1c3cc5d4

Comment by Robert Stam [ 24/May/16 ]

Actually, it should make no difference whether the extra characters are valid JSON or not.

We can argue that BsonDocument.Parse should check that it has consumed the entire string, and that ANY extra characters are an error.

Generated at Wed Feb 07 21:40:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.