-
Notifications
You must be signed in to change notification settings - Fork 912
GODRIVER-2017 Skip empty extJSON objects correctly in Unmarshal #677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bson/bsonrw/extjson_reader.go
Outdated
ejvr.p.advanceState() | ||
} | ||
depth-- | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to return
or continue
? what happens if we need to skip something with a nested empty document, something like
"UndefinedField": {"empty": {}, "key": 1}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continue
is more correct, but it actually doesn't change the parsing behavior 💭
In that example, the parser will realize UndefinedField
is undefined in the destination struct and will call skipObject
on the value of UndefinedField
: {"empty": {}, "key": 1}
. Since that value is not an empty object itself, the emptyObject
flag will not have been set, so the logic in this block won't actually apply. That said, continue
ing is more accurate than return
ing in my opinion, since the depth
variable will be set back to 0
and return anyway.
Also updated the existing test for "empty embedded document"
to be the case you described above.
hi guys, any update when this will be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, with a suggestion to extend the comment to describe a little more about the expected state(s) of the parser.
// If object is empty, raise depth and continue. If there is a comma, there are | ||
// remaining fields, emptyObject must be set back to false, and comma must be | ||
// skipped with advanceState(). | ||
if ejvr.p.emptyObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Add a description of the expected state of the parser/buffer to help people reading the code understand why we need different behavior for when ejvr.p.emptyObject
is true.
E.g.
When emptyObject is true, the parser has already read both the opening and closing brackets of an empty object ("{}"), so the next valid token will be part of the parent document, not part of the nested document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Added a description of the state of the parser (the exact text you gave).
Hi!
Next test loops in skipObject() function
|
GODRIVER-2017
Adds a case for empty objects in
extJSONValueReader#skipObject()
. Adds tests for empty objects in undefined fields forUnmarshalExtJSON
.Empty objects in extended JSON were being skipped without setting
ejvr.p.emptyObject
back tofalse
. So, a regular object following an empty object, as inwas being unmarshaled to an empty object even though it wasn't empty (i.e.
a
unmarshaled tobson.D{}
).