Skip to content

Commit

Permalink
Fix missed integer callback for zero
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmuskala authored and Ledest committed Jun 19, 2024
1 parent aed953b commit cc3b663
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/otpbp_json.erl
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,10 @@ number_zero(<<$., Rest/bits>>, Original, Skip, Acc, Stack, Decode, Len) ->
number_frac(Rest, Original, Skip, Acc, Stack, Decode, Len + 1);
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});
number_zero(Rest, Original, Skip, Acc, Stack, Decode, Len) ->
continue(Rest, Original, Skip + Len, Acc, Stack, Decode, 0).
number_zero(<<>>, Original, Skip, Acc, Stack, #decode{integer = Integer} = Decode, Len) ->
unexpected(Original, Skip, Acc, Stack, Decode, Len, 0, {number, Integer(<<"0">>)});
number_zero(Rest, Original, Skip, Acc, Stack, #decode{integer = Integer} = Decode, Len) ->
continue(Rest, Original, Skip + Len, Acc, Stack, Decode, Integer(<<"0">>)).

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 test/json_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ byte_loop(<<>>, State, _Bytes) -> json:decode_continue(end_of_input, State).

decode_api_test() ->
put(history, []),
?assertEqual({#{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three]},
{[], 24},
?assertEqual({#{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three, 0]},
{[], 25},
<<>>},
json:decode(<<"{\"a\": [[], {}, true, false, null, {\"foo\": \"baz\"}], \"b\": [1, 2.0, \"three\"]}">>,
json:decode(<<"{\"a\": [[], {}, true, false, null, {\"foo\": \"baz\"}], \"b\": [1, 2.0, \"three\", 0]}">>,
{[], 0},
#{array_start => set_history1(array_start, fun({_, Int}) -> {[], Int + 1} end),
array_push => set_history2(array_push, fun(Val, {Acc, Int}) -> {[Val|Acc], Int + 1} end),
Expand Down Expand Up @@ -374,15 +374,17 @@ decode_api_test() ->
{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}},
{integer, <<"0">>, 0},
{array_push, {0, {[three, 2.0, 1], 21}}, {[0, three, 2.0, 1], 22}},
{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}}},
{{[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], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 22}},
{[{b, [1, 2.0, three]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 23}},
{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}}}],
{{[{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}}}],
lists:reverse(get(history))).

set_history1(Ty, Fun) -> fun(Arg) -> set_history(Ty, Arg, Fun(Arg)) end.
Expand Down

0 comments on commit cc3b663

Please sign in to comment.