Skip to content

Commit

Permalink
Only perform multiple oneof check for non-null fields.
Browse files Browse the repository at this point in the history
This allows payloads like:
  {"oneofUint32": null, "oneofString": "test"}
  • Loading branch information
haberman committed Apr 15, 2021
1 parent 42bdfcb commit a778f26
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions upb/json_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,17 +939,17 @@ static void jsondec_field(jsondec *d, upb_msg *msg, const upb_msgdef *m) {
return;
}

if (upb_fielddef_realcontainingoneof(f) &&
upb_msg_whichoneof(msg, upb_fielddef_containingoneof(f))) {
jsondec_err(d, "More than one field for this oneof.");
}

if (jsondec_peek(d) == JD_NULL && !jsondec_isvalue(f)) {
/* JSON "null" indicates a default value, so no need to set anything. */
jsondec_null(d);
return;
}

if (upb_fielddef_realcontainingoneof(f) &&
upb_msg_whichoneof(msg, upb_fielddef_containingoneof(f))) {
jsondec_err(d, "More than one field for this oneof.");
}

preserved = d->debug_field;
d->debug_field = f;

Expand Down

0 comments on commit a778f26

Please sign in to comment.