the option single_quotes in functions dealing with json inputs now allows json that uses single quotes to deliminate keys and strings to be processed, note that this changes the escaping rules slightly
This commit is contained in:
parent
b3d9f5e6ff
commit
1d5b9e7410
5 changed files with 91 additions and 13 deletions
46
src/jsx.erl
46
src/jsx.erl
|
@ -120,6 +120,52 @@ encoder_decoder_equiv_test_() ->
|
|||
].
|
||||
|
||||
|
||||
single_quotes_test_() ->
|
||||
[
|
||||
{"single quoted keys",
|
||||
?_assertEqual(
|
||||
to_term(<<"{'key':true}">>, [single_quotes]),
|
||||
[{<<"key">>, true}]
|
||||
)
|
||||
},
|
||||
{"multiple single quoted keys",
|
||||
?_assertEqual(
|
||||
to_term(<<"{'key':true, 'another key':true}">>, [single_quotes]),
|
||||
[{<<"key">>, true}, {<<"another key">>, true}]
|
||||
)
|
||||
},
|
||||
{"nested single quoted keys",
|
||||
?_assertEqual(
|
||||
to_term(<<"{'key': {'key':true, 'another key':true}}">>, [single_quotes]),
|
||||
[{<<"key">>, [{<<"key">>, true}, {<<"another key">>, true}]}]
|
||||
)
|
||||
},
|
||||
{"single quoted string",
|
||||
?_assertEqual(
|
||||
to_term(<<"['string']">>, [single_quotes]),
|
||||
[<<"string">>]
|
||||
)
|
||||
},
|
||||
{"single quote in double quoted string",
|
||||
?_assertEqual(
|
||||
to_term(<<"[\"a single quote: '\"]">>),
|
||||
[<<"a single quote: '">>]
|
||||
)
|
||||
},
|
||||
{"escaped single quote in single quoted string",
|
||||
?_assertEqual(
|
||||
to_term(<<"['a single quote: \\'']">>, [single_quotes]),
|
||||
[<<"a single quote: '">>]
|
||||
)
|
||||
},
|
||||
{"escaped single quote when single quotes are disallowed",
|
||||
?_assertError(
|
||||
badarg,
|
||||
to_term(<<"[\"a single quote: \\'\"]">>)
|
||||
)
|
||||
}
|
||||
].
|
||||
|
||||
|
||||
%% test handler
|
||||
init([]) -> [].
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue