Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1235

Extended JSON can fail to parse if undefined document field contains a document or an array

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.4.5
    • Affects Version/s: None
    • Component/s: JSON & ExtJSON
    • Labels:

      NEW:

      If a source extjson document contains a document field that is not represented in the target struct and that document contains a nested document or array, unmarshalling can fail or incorrectly skip too many fields.

       

      ORIGINAL:

      The (extJSONValueReader).Skip() method fails when it tries to skip a document that has a document as a child. Specifically, the following test fails on the last line with the error "invalid request to read embedded document":

       

      func TestExtJSONValueReader_Skip(t *testing.T) {
          vr, err := NewExtJSONValueReader(strings.NewReader(`{"key": {"one": {"two": "three"}}}`), false)
          if err != nil {
                t.Fatalf("error creating vr: %v", err)
          }
      
          dr, err := vr.ReadDocument()
          if err != nil {
              t.Fatalf("error reading doc: %v", err)
          }
      
          _, vr, err = dr.ReadElement()
          if err != nil {
              t.Fatalf("error reading element: %v", err)
          }
      
          err = vr.Skip()
          if err != nil {
              t.Fatalf("error skipping: %v", err)
          }
      }

       

      That error comes from the extJSONParser.readValue() method which cannot read a whole embedded document. I believe the fix for this is to check in Skip() if the type is an embedded document and handle it appropriately there.

            Assignee:
            benji.rewis@mongodb.com Benji Rewis (Inactive)
            Reporter:
            matthew.chiaravalloti@mongodb.com Matthew Chiaravalloti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: