allow a single trailing comma in objects or arrays
This commit is contained in:
parent
c25bb49902
commit
6b43609730
4 changed files with 56 additions and 0 deletions
|
@ -211,6 +211,8 @@ value(<<?start_array, Rest/binary>>, Handler, Stack, Config) ->
|
|||
array(Rest, handle_event(start_array, Handler, Config), [array|Stack], Config);
|
||||
value(<<S, Rest/binary>>, Handler, Stack, Config) when ?is_whitespace(S) ->
|
||||
value(Rest, Handler, Stack, Config);
|
||||
value(<<?end_array, _/binary>> = Rest, Handler, Stack, Config=#config{strict_commas=false}) ->
|
||||
maybe_done(Rest, Handler, Stack, Config);
|
||||
value(<<?solidus, Rest/binary>>, Handler, Stack, Config=#config{strict_comments=true}) ->
|
||||
?error(value, <<?solidus, Rest/binary>>, Handler, Stack, Config);
|
||||
value(<<?solidus, ?solidus, Rest/binary>>, Handler, Stack, Config) ->
|
||||
|
@ -289,6 +291,8 @@ key(<<?singlequote, Rest/binary>>, Handler, Stack, Config=#config{strict_single_
|
|||
string(Rest, Handler, new_seq(), [singlequote|Stack], Config);
|
||||
key(<<S, Rest/binary>>, Handler, Stack, Config) when ?is_whitespace(S) ->
|
||||
key(Rest, Handler, Stack, Config);
|
||||
key(<<?end_object, Rest/binary>>, Handler, [key|Stack], Config=#config{strict_commas=false}) ->
|
||||
maybe_done(<<?end_object, Rest/binary>>, Handler, [object|Stack], Config);
|
||||
key(<<?solidus, Rest/binary>>, Handler, Stack, Config=#config{strict_comments=true}) ->
|
||||
?error(key, <<?solidus, Rest/binary>>, Handler, Stack, Config);
|
||||
key(<<?solidus, ?solidus, Rest/binary>>, Handler, Stack, Config) ->
|
||||
|
@ -1627,6 +1631,43 @@ bom_test_() ->
|
|||
].
|
||||
|
||||
|
||||
trailing_comma_test_() ->
|
||||
[
|
||||
{"trailing comma in object", ?_assertEqual(
|
||||
[start_object, {key, <<"key">>}, {literal, true}, end_object, end_json],
|
||||
decode(<<"{\"key\": true,}">>, [])
|
||||
)},
|
||||
{"strict trailing comma in object", ?_assertError(
|
||||
badarg,
|
||||
decode(<<"{\"key\": true,}">>, [{strict, [trailing_commas]}])
|
||||
)},
|
||||
{"two trailing commas in object", ?_assertError(
|
||||
badarg,
|
||||
decode(<<"{\"key\": true,,}">>, [])
|
||||
)},
|
||||
{"comma in empty object", ?_assertError(
|
||||
badarg,
|
||||
decode(<<"{,}">>, [])
|
||||
)},
|
||||
{"trailing comma in list", ?_assertEqual(
|
||||
[start_array, {literal, true}, end_array, end_json],
|
||||
decode(<<"[true,]">>, [])
|
||||
)},
|
||||
{"strict trailing comma in list", ?_assertError(
|
||||
badarg,
|
||||
decode(<<"[true,]">>, [{strict, [trailing_commas]}])
|
||||
)},
|
||||
{"two trailing commas in list", ?_assertError(
|
||||
badarg,
|
||||
decode(<<"[true,,]">>, [])
|
||||
)},
|
||||
{"comma in empty list", ?_assertError(
|
||||
badarg,
|
||||
decode(<<"[,]">>, [])
|
||||
)}
|
||||
].
|
||||
|
||||
|
||||
incomplete_test_() ->
|
||||
[
|
||||
{"stream false", ?_assertError(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue