[GODRIVER-1235] Extended JSON can fail to parse if undefined document field contains a document or an array Created: 13/Aug/19  Updated: 28/Oct/23  Resolved: 09/Dec/20

Status: Closed
Project: Go Driver
Component/s: JSON & ExtJSON
Affects Version/s: None
Fix Version/s: 1.4.5

Type: Bug Priority: Major - P3
Reporter: Matthew Chiaravalloti Assignee: Benji Rewis (Inactive)
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by GODRIVER-1797 Undefined attribute that is an array ... Closed
Related
related to GODRIVER-1797 Undefined attribute that is an array ... Closed

 Description   

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.



 Comments   
Comment by Githook User [ 09/Dec/20 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-1235 Skip embedded documents and arrays correctly in extJSONValueReader (#544)
Branch: release/1.4
https://github.com/mongodb/mongo-go-driver/commit/b10e63995e95ee9d1f0cd49852367c8c7f7bdec4

Comment by Githook User [ 09/Dec/20 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-1235 Skip embedded documents and arrays correctly in extJSONValueReader (#544)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/cbd454067de8c9202162bc2f7d867fdfc5a0941c

Comment by Benji Rewis (Inactive) [ 30/Nov/20 ]

https://github.com/mongodb/mongo-go-driver/pull/544

Generated at Thu Feb 08 08:35:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.