From 522f72b2ce008f1db43c253801bef32f9e71e57c Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Thu, 17 Sep 2015 15:25:03 -0500 Subject: [PATCH] mask a `function_clause' error in encoder with a `badarg' error for api unity --- CHANGES.md | 5 +++++ src/jsx_encoder.erl | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 9430e79..23f866b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +v2.7.2 + +* fix an issue where tuples were assumed to be jsx ast and not checked +* mask a `function_clause` error in encoder with a `badarg` error for api unity + v2.7.1 * support for milliseconds in datetimes diff --git a/src/jsx_encoder.erl b/src/jsx_encoder.erl index e89328c..39140d8 100644 --- a/src/jsx_encoder.erl +++ b/src/jsx_encoder.erl @@ -67,7 +67,8 @@ encode_(Else, _EntryPoint) -> [Else]. unzip([{K, V}|Rest], EntryPoint) when is_integer(K); is_binary(K); is_atom(K) -> [K] ++ EntryPoint:encode(V, EntryPoint) ++ unzip(Rest, EntryPoint); -unzip([], _) -> [end_object]. +unzip([], _) -> [end_object]; +unzip(_, _) -> erlang:error(badarg). unhitch([V|Rest], EntryPoint) -> @@ -111,4 +112,16 @@ custom_error_handler_test_() -> )} ]. +improper_lists_test_() -> + [ + {"improper proplist", ?_assertError( + badarg, + encode([{<<"key">>, <<"value">>}, false]) + )}, + {"improper list", ?_assertError( + badarg, + encode([{literal, true}, false, null]) + )} + ]. + -endif.