introduce option to skip checking for repeated keys

This commit is contained in:
alisdair sullivan 2014-08-26 22:28:44 -07:00
parent 5d184327e4
commit e2ef23a46a
4 changed files with 24 additions and 1 deletions

View file

@ -63,6 +63,8 @@ parse_config([unescaped_jsonp|Rest], Config) ->
parse_config(Rest, Config#config{unescaped_jsonp=true});
parse_config([dirty_strings|Rest], Config) ->
parse_config(Rest, Config#config{dirty_strings=true});
parse_config([repeat_keys|Rest], Config) ->
parse_config(Rest, Config#config{repeat_keys=true});
parse_config([strict|Rest], Config) ->
parse_config(Rest, Config#config{strict_comments=true,
strict_commas=true,
@ -146,6 +148,7 @@ valid_flags() ->
escaped_strings,
unescaped_jsonp,
dirty_strings,
repeat_keys,
strict,
stream,
error_handler,
@ -184,6 +187,7 @@ config_test_() ->
escaped_strings = true,
unescaped_jsonp = true,
dirty_strings = true,
repeat_keys = true,
strict_comments = true,
strict_commas = true,
strict_utf8 = true,
@ -195,6 +199,7 @@ config_test_() ->
escaped_strings,
unescaped_jsonp,
dirty_strings,
repeat_keys,
strict,
stream
])
@ -264,6 +269,7 @@ config_to_list_test_() ->
escaped_strings,
unescaped_jsonp,
dirty_strings,
repeat_keys,
stream,
strict
],
@ -272,6 +278,7 @@ config_to_list_test_() ->
escaped_strings = true,
unescaped_jsonp = true,
dirty_strings = true,
repeat_keys = true,
strict_comments = true,
strict_utf8 = true,
strict_single_quotes = true,

View file

@ -3,6 +3,7 @@
escaped_strings = false :: boolean(),
unescaped_jsonp = false :: boolean(),
dirty_strings = false :: boolean(),
repeat_keys = false :: boolean(),
strict_comments = false :: boolean(),
strict_commas = false :: boolean(),
strict_utf8 = false :: boolean(),

View file

@ -141,6 +141,19 @@ object([end_object|Tokens], Handler, [{object, _}|Stack], Config) ->
object([{key, Key}|Tokens], Handler, Stack, Config)
when is_atom(Key); is_binary(Key); is_integer(Key) ->
object([Key|Tokens], Handler, Stack, Config);
object([Key|Tokens], Handler, [{object, _Keys}|Stack], Config=#config{repeat_keys=true})
when is_atom(Key); is_binary(Key); is_integer(Key) ->
try clean_string(fix_key(Key), Config)
of K ->
value(
Tokens,
handle_event({key, K}, Handler, Config),
[{object, []}|Stack],
Config
)
catch error:badarg ->
?error(object, [{string, Key}|Tokens], Handler, Stack, Config)
end;
object([Key|Tokens], Handler, [{object, Keys}|Stack], Config)
when is_atom(Key); is_binary(Key); is_integer(Key) ->
try