Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1676

BsonDocument.Parse and multiple JSON values

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.3
    • Affects Version/s: 2.2.4
    • Component/s: BSON
    • None
    • Minor Change

      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.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: