From a778f2639a0914c0430b44f61c36fbc85f4fd5b3 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 15 Apr 2021 14:02:55 -0700 Subject: [PATCH] Only perform multiple oneof check for non-null fields. This allows payloads like: {"oneofUint32": null, "oneofString": "test"} --- upb/json_decode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/upb/json_decode.c b/upb/json_decode.c index 732a0c653a..b574a17817 100644 --- a/upb/json_decode.c +++ b/upb/json_decode.c @@ -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;