From 9f0ababed2ed9f6aa8a0f4db81c66ea8d5c03c34 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Thu, 8 Jun 2017 13:45:57 +0100 Subject: [PATCH 1/3] Fix typo in readme on utf8 option --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37590e9..108a125 100644 --- a/README.md +++ b/README.md @@ -440,7 +440,7 @@ additional options beyond these. see escape sequences not adhering to the json spec result in a `badarg` error any combination of these can be passed to **jsx** by using `{strict, [strict_option()]}`. - `strict` is equivalent to `{strict, [comments, bad_utf8, single_quotes, escapes]}` + `strict` is equivalent to `{strict, [comments, utf8, single_quotes, escapes]}` - `return_tail` From 1e80a36061d52155c5a8fddb56228c820d100288 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Thu, 8 Jun 2017 13:56:15 +0100 Subject: [PATCH 2/3] Correct documentation of semantics of `strict` option See https://github.com/talentdeficit/jsx/blob/2.8.2/src/jsx_config.erl#L78 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 108a125..9f72709 100644 --- a/README.md +++ b/README.md @@ -440,7 +440,7 @@ additional options beyond these. see escape sequences not adhering to the json spec result in a `badarg` error any combination of these can be passed to **jsx** by using `{strict, [strict_option()]}`. - `strict` is equivalent to `{strict, [comments, utf8, single_quotes, escapes]}` + `strict` is equivalent to `{strict, [comments, trailing_commas, utf8, single_quotes, escapes]}` - `return_tail` From 48574d42427c66b454000a6851a9de7ba6618dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Tue, 26 Sep 2017 10:10:24 +0200 Subject: [PATCH 3/3] jsx_to_term:parse_config/2: Honor `return_maps` option value Previously, no matter what the caller specified in options, `return_maps` was always set to `true`. The only solution was to not specify `return_maps` at all. Unfortunately, if the caller is using a wrapper which sets default options, including `return_maps`, it's impossible to override it. This prevented the caller from requesting this mode if he was interested in preserving the order of keys. While here, add a testcase for this. --- src/jsx_to_term.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jsx_to_term.erl b/src/jsx_to_term.erl index aa05264..e4e5f5e 100644 --- a/src/jsx_to_term.erl +++ b/src/jsx_to_term.erl @@ -88,7 +88,7 @@ parse_config([labels|Rest], Config) -> parse_config(Rest, Config#config{labels = binary}); parse_config([{return_maps, Val}|Rest], Config) when Val == true; Val == false -> - parse_config(Rest, Config#config{return_maps = true}); + parse_config(Rest, Config#config{return_maps = Val}); parse_config([return_maps|Rest], Config) -> parse_config(Rest, Config#config{return_maps = true}); parse_config([{K, _}|Rest] = Options, Config) -> @@ -424,6 +424,10 @@ return_maps_test_() -> [{}], jsx:decode(<<"{}">>, []) )}, + {"an empty map", ?_assertEqual( + [{}], + jsx:decode(<<"{}">>, [{return_maps, false}]) + )}, {"a small map", ?_assertEqual( #{<<"awesome">> => true, <<"library">> => <<"jsx">>}, jsx:decode(<<"{\"library\": \"jsx\", \"awesome\": true}">>, [return_maps])