Skip to content

Commit

Permalink
Expect fail when serialize inf and nan for Value.number_value in json…
Browse files Browse the repository at this point in the history
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500828964
  • Loading branch information
anandolee authored and copybara-github committed Jan 9, 2023
1 parent 87f9b86 commit 651550c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions upb/json/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ static void jsonenc_value(jsonenc* e, const upb_Message* msg,
jsonenc_putstr(e, "null");
break;
case 2:
if (upb_JsonEncode_HandleSpecialDoubles(e, val.double_val)) {
jsonenc_err(
e,
"google.protobuf.Value cannot encode double values for "
"infinity or nan, because they would be parsed as a string");
}
upb_JsonEncode_Double(e, val.double_val);
break;
case 3:
Expand Down

0 comments on commit 651550c

Please sign in to comment.