BsonDocument.Parse and multiple JSON values

XMLWordPrintableJSON

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

      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 Stam
            Reporter:
            Wan Bachtiar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: