File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -376,8 +376,18 @@ defmodule Protobuf.JSON.Decode do
376376
377377 defp parse_int ( string ) do
378378 case Integer . parse ( string ) do
379- { int , "" } -> { :ok , int }
380- _ -> :error
379+ { int , "" } ->
380+ { :ok , int }
381+
382+ _ ->
383+ # We accept integers in scientific notation as well:
384+ case Float . parse ( string ) do
385+ { float , "" } ->
386+ parse_float_as_int ( float )
387+
388+ _ ->
389+ :error
390+ end
381391 end
382392 end
383393
Original file line number Diff line number Diff line change @@ -83,6 +83,12 @@ defmodule Protobuf.ConformanceRegressionsTest do
8383
8484 @ describetag message_type: "protobuf_test_messages.proto3.TestAllTypesProto3"
8585
86+ test "Required.Proto3.JsonInput.Int32FieldQuotedExponentialValue.JsonOutput" do
87+ mod = ProtobufTestMessages.Proto3.TestAllTypesProto3
88+ problematic_payload = ~S( {"optionalInt32": "1e5"})
89+ assert % { optional_int32: 100_000 } = Protobuf.JSON . decode! ( problematic_payload , mod )
90+ end
91+
8692 test "Recommended.Proto3.JsonInput.NullValueInOtherOneofNewFormat.Validator" ,
8793 % { message_mod: message_mod } do
8894 json = "{\" oneofNullValue\" : null}"
You can’t perform that action at this time.
0 commit comments