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
376
376
377
377
defp parse_int ( string ) do
378
378
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
381
391
end
382
392
end
383
393
Original file line number Diff line number Diff line change @@ -83,6 +83,12 @@ defmodule Protobuf.ConformanceRegressionsTest do
83
83
84
84
@ describetag message_type: "protobuf_test_messages.proto3.TestAllTypesProto3"
85
85
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
+
86
92
test "Recommended.Proto3.JsonInput.NullValueInOtherOneofNewFormat.Validator" ,
87
93
% { message_mod: message_mod } do
88
94
json = "{\" oneofNullValue\" : null}"
You can’t perform that action at this time.
0 commit comments