previously, unambiguously incomplete input was sometimes treated as ambiguous. the 'incomplete_input' flag is no longer needed to parse this input correctly
This commit is contained in:
parent
6ff94d8e5f
commit
844ee2407f
2 changed files with 83 additions and 8 deletions
75
src/jsx.erl
75
src/jsx.erl
|
@ -179,6 +179,81 @@ encoder_decoder_equiv_test_() ->
|
||||||
].
|
].
|
||||||
|
|
||||||
|
|
||||||
|
partial_numbers_test_() ->
|
||||||
|
[
|
||||||
|
{"partial integer",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"integer\": 12345">>),
|
||||||
|
F(<<"67890}">>)
|
||||||
|
end =:= [{<<"integer">>, 1234567890}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial integer",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"integer\": 1234567890">>),
|
||||||
|
F(<<"}">>)
|
||||||
|
end =:= [{<<"integer">>, 1234567890}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial float",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"float\": 1.">>),
|
||||||
|
F(<<"23}">>)
|
||||||
|
end =:= [{<<"float">>, 1.23}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial float",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"float\": 1.2">>),
|
||||||
|
F(<<"3}">>)
|
||||||
|
end =:= [{<<"float">>, 1.23}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial float",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"float\": 1.23">>),
|
||||||
|
F(<<"}">>)
|
||||||
|
end =:= [{<<"float">>, 1.23}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial exp",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"exp\": 1.0e">>),
|
||||||
|
F(<<"1}">>)
|
||||||
|
end =:= [{<<"exp">>, 10.0}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial exp",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"exp\": 1.0e1">>),
|
||||||
|
F(<<"2}">>)
|
||||||
|
end =:= [{<<"exp">>, 1.0e12}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial exp",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"exp\": 1.0e1">>),
|
||||||
|
F(<<"}">>)
|
||||||
|
end =:= [{<<"exp">>, 10.0}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial zero",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"zero\": 0">>),
|
||||||
|
F(<<".0}">>)
|
||||||
|
end =:= [{<<"zero">>, 0.0}]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"partial zero",
|
||||||
|
?_assert(begin
|
||||||
|
{incomplete, F} = jsx:decode(<<"{\"zero\": 0">>),
|
||||||
|
F(<<"}">>)
|
||||||
|
end =:= [{<<"zero">>, 0}]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
].
|
||||||
|
|
||||||
|
|
||||||
single_quoted_strings_test_() ->
|
single_quoted_strings_test_() ->
|
||||||
[
|
[
|
||||||
{"single quoted keys",
|
{"single quoted keys",
|
||||||
|
|
|
@ -748,8 +748,8 @@ zero(<<S, Rest/binary>>, Handler, [Acc|Stack], Opts) when ?is_whitespace(S) ->
|
||||||
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
||||||
zero(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
|
zero(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
|
||||||
comment(Rest, handle_event(format_number(Acc), Handler, Opts), [maybe_done|Stack], Opts);
|
comment(Rest, handle_event(format_number(Acc), Handler, Opts), [maybe_done|Stack], Opts);
|
||||||
zero(<<>>, Handler, [Acc|Stack], Opts = #opts{explicit_end=false}) ->
|
zero(<<>>, Handler, [Acc|[]], Opts = #opts{explicit_end=false}) ->
|
||||||
maybe_done(<<>>, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
maybe_done(<<>>, handle_event(format_number(Acc), Handler, Opts), [], Opts);
|
||||||
zero(<<>>, Handler, Stack, Opts) ->
|
zero(<<>>, Handler, Stack, Opts) ->
|
||||||
?incomplete(zero, <<>>, Handler, Stack, Opts);
|
?incomplete(zero, <<>>, Handler, Stack, Opts);
|
||||||
zero(Bin, Handler, Stack, Opts) ->
|
zero(Bin, Handler, Stack, Opts) ->
|
||||||
|
@ -776,8 +776,8 @@ integer(<<S, Rest/binary>>, Handler, [Acc|Stack], Opts) when ?is_whitespace(S) -
|
||||||
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
||||||
integer(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
|
integer(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
|
||||||
comment(Rest, handle_event(format_number(Acc), Handler, Opts), [maybe_done|Stack], Opts);
|
comment(Rest, handle_event(format_number(Acc), Handler, Opts), [maybe_done|Stack], Opts);
|
||||||
integer(<<>>, Handler, [Acc|Stack], Opts = #opts{explicit_end=false}) ->
|
integer(<<>>, Handler, [Acc|[]], Opts = #opts{explicit_end=false}) ->
|
||||||
maybe_done(<<>>, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
maybe_done(<<>>, handle_event(format_number(Acc), Handler, Opts), [], Opts);
|
||||||
integer(<<>>, Handler, Stack, Opts) ->
|
integer(<<>>, Handler, Stack, Opts) ->
|
||||||
?incomplete(integer, <<>>, Handler, Stack, Opts);
|
?incomplete(integer, <<>>, Handler, Stack, Opts);
|
||||||
integer(Bin, Handler, Stack, Opts) ->
|
integer(Bin, Handler, Stack, Opts) ->
|
||||||
|
@ -809,8 +809,8 @@ decimal(<<S, Rest/binary>>, Handler, [Acc|Stack], Opts) when ?is_whitespace(S) -
|
||||||
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
||||||
decimal(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
|
decimal(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
|
||||||
comment(Rest, handle_event(format_number(Acc), Handler, Opts), [maybe_done|Stack], Opts);
|
comment(Rest, handle_event(format_number(Acc), Handler, Opts), [maybe_done|Stack], Opts);
|
||||||
decimal(<<>>, Handler, [Acc|Stack], Opts = #opts{explicit_end=false}) ->
|
decimal(<<>>, Handler, [Acc|[]], Opts = #opts{explicit_end=false}) ->
|
||||||
maybe_done(<<>>, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
maybe_done(<<>>, handle_event(format_number(Acc), Handler, Opts), [], Opts);
|
||||||
decimal(<<>>, Handler, Stack, Opts) ->
|
decimal(<<>>, Handler, Stack, Opts) ->
|
||||||
?incomplete(decimal, <<>>, Handler, Stack, Opts);
|
?incomplete(decimal, <<>>, Handler, Stack, Opts);
|
||||||
decimal(Bin, Handler, Stack, Opts) ->
|
decimal(Bin, Handler, Stack, Opts) ->
|
||||||
|
@ -849,8 +849,8 @@ exp(<<S, Rest/binary>>, Handler, [Acc|Stack], Opts) when ?is_whitespace(S) ->
|
||||||
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
||||||
exp(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
|
exp(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
|
||||||
comment(Rest, handle_event(format_number(Acc), Handler, Opts), [maybe_done|Stack], Opts);
|
comment(Rest, handle_event(format_number(Acc), Handler, Opts), [maybe_done|Stack], Opts);
|
||||||
exp(<<>>, Handler, [Acc|Stack], Opts = #opts{explicit_end=false}) ->
|
exp(<<>>, Handler, [Acc|[]], Opts = #opts{explicit_end=false}) ->
|
||||||
maybe_done(<<>>, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
|
maybe_done(<<>>, handle_event(format_number(Acc), Handler, Opts), [], Opts);
|
||||||
exp(<<>>, Handler, Stack, Opts) ->
|
exp(<<>>, Handler, Stack, Opts) ->
|
||||||
?incomplete(exp, <<>>, Handler, Stack, Opts);
|
?incomplete(exp, <<>>, Handler, Stack, Opts);
|
||||||
exp(Bin, Handler, Stack, Opts) ->
|
exp(Bin, Handler, Stack, Opts) ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue