Skip to content

Commit

Permalink
http://code.google.com/p/mochiweb/issues/detail?id=55
Browse files Browse the repository at this point in the history
git-svn-id: http://mochiweb.googlecode.com/svn/trunk@121 583d1f64-3c3e-0410-8459-0f15fcd77d59
  • Loading branch information
bob.ippolito committed Jan 2, 2010
1 parent fc8ea22 commit 2ab80b0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/mochijson2.erl
Expand Up @@ -38,8 +38,9 @@
%% @type json_number() = integer() | float()
%% @type json_array() = [json_term()]
%% @type json_object() = {struct, [{json_string(), json_term()}]}
%% @type json_iolist() = {json, iolist()}
%% @type json_term() = json_string() | json_number() | json_array() |
%% json_object()
%% json_object() | json_iolist()

-record(encoder, {handler=null,
utf8=false}).
Expand Down Expand Up @@ -107,6 +108,8 @@ json_encode(Array, State) when is_list(Array) ->
json_encode_array(Array, State);
json_encode({struct, Props}, State) when is_list(Props) ->
json_encode_proplist(Props, State);
json_encode({json, IoList}, _State) ->
IoList;
json_encode(Bad, #encoder{handler=null}) ->
exit({json_encode, {bad_term, Bad}});
json_encode(Bad, State=#encoder{handler=Handler}) ->
Expand Down Expand Up @@ -664,4 +667,14 @@ input_validation_test() ->
ok = try decode(X) catch invalid_utf8 -> ok end
end, Bad).

inline_json_test() ->
?assertEqual(<<"\"iodata iodata\"">>,
iolist_to_binary(
encode({json, [<<"\"iodata">>, " iodata\""]}))),
?assertEqual({struct, [{<<"key">>, <<"iodata iodata">>}]},
decode(
encode({struct,
[{key, {json, [<<"\"iodata">>, " iodata\""]}}]}))),
ok.

-endif.

0 comments on commit 2ab80b0

Please sign in to comment.