modified jsx_parser to reject bare json values, fixed typo
This commit is contained in:
parent
2cf20cf809
commit
5f5be51365
1 changed files with 7 additions and 2 deletions
|
@ -37,7 +37,7 @@ decode(JSON) ->
|
||||||
{incomplete, _} ->
|
{incomplete, _} ->
|
||||||
{error, badjson}
|
{error, badjson}
|
||||||
; {error, badjson} ->
|
; {error, badjson} ->
|
||||||
{error, badjosn}
|
{error, badjson}
|
||||||
; {Result, _} ->
|
; {Result, _} ->
|
||||||
Result
|
Result
|
||||||
end.
|
end.
|
||||||
|
@ -46,7 +46,7 @@ decode(JSON) ->
|
||||||
%% erlang representation is dicts for objects and lists for arrays. these are pushed
|
%% erlang representation is dicts for objects and lists for arrays. these are pushed
|
||||||
%% onto a stack, the top of which is our current level, deeper levels represent parent
|
%% onto a stack, the top of which is our current level, deeper levels represent parent
|
||||||
%% and grandparent levels in the json structure. keys are also stored on top of the array
|
%% and grandparent levels in the json structure. keys are also stored on top of the array
|
||||||
%% during parsing of their associated values.
|
%% during parsing of their associated values.
|
||||||
|
|
||||||
event(start_object, Stack) ->
|
event(start_object, Stack) ->
|
||||||
[dict:new()] ++ Stack;
|
[dict:new()] ++ Stack;
|
||||||
|
@ -72,6 +72,11 @@ event(end_array, [Array]) ->
|
||||||
event({key, Key}, [Object|Stack]) ->
|
event({key, Key}, [Object|Stack]) ->
|
||||||
[{key, Key}] ++ [Object] ++ Stack;
|
[{key, Key}] ++ [Object] ++ Stack;
|
||||||
|
|
||||||
|
%% reject values that aren't wrapped by an array or object
|
||||||
|
|
||||||
|
event({_Type, _Value}, []) ->
|
||||||
|
erlang:error(badjson);
|
||||||
|
|
||||||
%% this is kind of a dirty hack, but erlang will interpret atoms when applied to (Args)
|
%% this is kind of a dirty hack, but erlang will interpret atoms when applied to (Args)
|
||||||
%% as a function. so naming our formatting functions string, number and literal will
|
%% as a function. so naming our formatting functions string, number and literal will
|
||||||
%% allow the following shortcut
|
%% allow the following shortcut
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue