Skip to content

Commit

Permalink
[json] Fix missed integer callback for zero
Browse files Browse the repository at this point in the history
Summary:

Test Plan:
  • Loading branch information
[email protected] committed Jun 14, 2024
1 parent 56ca964 commit 5e2055c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/stdlib/src/json.erl
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,11 @@ number_zero(<<$., Rest/bits>>, Original, Skip, Acc, Stack, Decode, Len) ->
number_zero(<<E, Rest/bits>>, Original, Skip, Acc, Stack, Decode, Len) when E =:= $E; E =:= $e ->
number_exp_copy(Rest, Original, Skip, Acc, Stack, Decode, Len + 1, <<"0">>);
number_zero(<<>>, Original, Skip, Acc, Stack, Decode, Len) ->
unexpected(Original, Skip, Acc, Stack, Decode, Len, 0, {number, 0});
Value = (Decode#decode.integer)(<<"0">>),
unexpected(Original, Skip, Acc, Stack, Decode, Len, 0, {number, Value});
number_zero(Rest, Original, Skip, Acc, Stack, Decode, Len) ->
continue(Rest, Original, Skip+Len, Acc, Stack, Decode, 0).
Value = (Decode#decode.integer)(<<"0">>),
continue(Rest, Original, Skip+Len, Acc, Stack, Decode, Value).

number(<<Num, Rest/bits>>, Original, Skip, Acc, Stack, Decode, Len) when ?is_0_to_9(Num) ->
number(Rest, Original, Skip, Acc, Stack, Decode, Len + 1);
Expand Down
20 changes: 11 additions & 9 deletions lib/stdlib/test/json_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ test_decode_api(_Config) ->
null => nil
},

Data = <<"{\"a\": [[], {}, true, false, null, {\"foo\": \"baz\"}], \"b\": [1, 2.0, \"three\"]}">>,
Data = <<"{\"a\": [[], {}, true, false, null, {\"foo\": \"baz\"}], \"b\": [1, 2.0, \"three\", 0]}">>,
{Decoded, Acc, <<>>} = json:decode(Data, {[], 0}, Decoders),
?assertEqual({[], 24}, Acc),
Expected = #{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three]},
?assertEqual({[], 25}, Acc),
Expected = #{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three, 0]},
?assertEqual(Expected, Decoded),
ExpectedHistory =
[
Expand Down Expand Up @@ -523,13 +523,15 @@ test_decode_api(_Config) ->
{array_push, {2.0, {[1], 19}}, {[2.0, 1], 20}},
{string, <<"three">>, three},
{array_push, {three, {[2.0, 1], 20}}, {[three, 2.0, 1], 21}},
{array_finish, {{[three, 2.0, 1], 21}, {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 17}},
{[1, 2.0, three], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 22}}},
{object_push, {b, [1, 2.0, three], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 22}}, {
[{b, [1, 2.0, three]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 23
{integer, <<"0">>, 0},
{array_push, {0, {[three, 2.0, 1], 21}}, {[0, three, 2.0, 1], 22}},
{array_finish, {{[0, three, 2.0, 1], 22}, {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 17}},
{[1, 2.0, three, 0], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 23}}},
{object_push, {b, [1, 2.0, three, 0], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 23}}, {
[{b, [1, 2.0, three, 0]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 24
}},
{object_finish, {{[{b, [1, 2.0, three]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 23}, {[], 0}},
{#{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three]}, {[], 24}}}
{object_finish, {{[{b, [1, 2.0, three, 0]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 24}, {[], 0}},
{#{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three, 0]}, {[], 25}}}
],
?assertEqual(ExpectedHistory, lists:reverse(get(history))).

Expand Down

0 comments on commit 5e2055c

Please sign in to comment.