incomplete input now results in an error when parsing json or jsx
internal form streaming decoding is now only available when forced with the `stream` option and no longer returns until forced to via the token `end_stream`. this api is still subject to being replaced with an even more explicit streaming mode
This commit is contained in:
parent
6797bf3ed7
commit
e4a401a3a6
2 changed files with 30 additions and 2 deletions
|
@ -138,10 +138,15 @@ resume(Rest, State, Handler, Acc, Stack, Config) ->
|
|||
-endif.
|
||||
|
||||
|
||||
incomplete(State, Rest, Handler, Stack, Config = #config{stream=false}) ->
|
||||
?error(State, Rest, Handler, Stack, Config);
|
||||
incomplete(State, Rest, Handler, Stack, Config) ->
|
||||
incomplete(State, Rest, Handler, unused, Stack, Config).
|
||||
|
||||
incomplete(State, Rest, Handler, Acc, Stack, Config=#config{incomplete_handler=false}) ->
|
||||
|
||||
incomplete(State, Rest, Handler, Acc, Stack, Config = #config{stream=false}) ->
|
||||
?error(State, Rest, Handler, Acc, Stack, Config);
|
||||
incomplete(State, Rest, Handler, Acc, Stack, Config = #config{incomplete_handler=false}) ->
|
||||
{incomplete, fun(Stream) when is_binary(Stream) ->
|
||||
resume(<<Rest/binary, Stream/binary>>, State, Handler, Acc, Stack, Config);
|
||||
(end_stream) ->
|
||||
|
@ -151,7 +156,7 @@ incomplete(State, Rest, Handler, Acc, Stack, Config=#config{incomplete_handler=f
|
|||
end
|
||||
end
|
||||
};
|
||||
incomplete(State, Rest, Handler, Acc, Stack, Config=#config{incomplete_handler=F}) ->
|
||||
incomplete(State, Rest, Handler, Acc, Stack, Config = #config{incomplete_handler=F}) ->
|
||||
F(Rest, {decoder, State, Handler, Acc, Stack}, jsx_config:config_to_list(Config)).
|
||||
|
||||
|
||||
|
@ -1898,6 +1903,27 @@ bom_test_() ->
|
|||
].
|
||||
|
||||
|
||||
incomplete_test_() ->
|
||||
[
|
||||
{"stream false", ?_assertError(
|
||||
badarg,
|
||||
start(<<"{">>, {jsx, []}, [], jsx_config:parse_config([]))
|
||||
)},
|
||||
{"stream true", ?_assert(
|
||||
case start(<<"{">>, {jsx, []}, [], jsx_config:parse_config([stream])) of
|
||||
{incomplete, _} -> true;
|
||||
_ -> false
|
||||
end
|
||||
)},
|
||||
{"complete input", ?_assert(
|
||||
case start(<<"{}">>, {jsx, []}, [], jsx_config:parse_config([stream])) of
|
||||
{incomplete, _} -> true;
|
||||
_ -> false
|
||||
end
|
||||
)}
|
||||
].
|
||||
|
||||
|
||||
error_test_() ->
|
||||
Decode = fun(JSON, Config) -> start(JSON, {jsx, []}, [], jsx_config:parse_config(Config)) end,
|
||||
[
|
||||
|
|
|
@ -72,6 +72,8 @@ resume(Rest, State, Handler, Stack, Config) ->
|
|||
-endif.
|
||||
|
||||
|
||||
incomplete(State, Handler, Stack, Config=#config{stream=false}) ->
|
||||
?error(State, [], Handler, Stack, Config);
|
||||
incomplete(State, Handler, Stack, Config=#config{incomplete_handler=false}) ->
|
||||
{incomplete, fun(end_stream) ->
|
||||
case resume([end_json], State, Handler, Stack, Config) of
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue