Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions c_src/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,25 @@ encode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
ret = enc_obj_error(e, "invalid_object_member_arity", item);
goto done;
}
if(!enc_string(e, tuple[0])) {
ret = enc_obj_error(e, "invalid_object_member_key", tuple[0]);
goto done;
if(enif_get_int64(env, tuple[0], &lval)) {
if (!enc_char(e, '"')) {
ret = enc_error(e, "internal_error");
goto done;
}
if(!enc_long(e, lval)) {
ret = enc_obj_error(e, "invalid_object_member_key", tuple[0]);
goto done;
}
if (!enc_char(e, '"')) {
ret = enc_error(e, "internal_error");
goto done;
}
}
else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: This "else {" should be moved up to the previous line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks, I'll tidy up and resubmit PR

if(!enc_string(e, tuple[0])) {
ret = enc_obj_error(e, "invalid_object_member_key", tuple[0]);
goto done;
}
}
if(!enc_colon(e)) {
ret = enc_error(e, "internal_error");
Expand Down
13 changes: 12 additions & 1 deletion test/jiffy_07_compound_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@


compound_success_test_() ->
[gen(ok, Case) || Case <- cases(ok)].
[gen(ok, Case) || Case <- cases(ok)] ++
[gen(special_encoding, Case) || Case <- cases(special_encoding)].


compound_failure_test_() ->
Expand All @@ -24,6 +25,11 @@ gen(ok, {J1, E, J2}) ->
{"Encode", ?_assertEqual(J2, enc(E))}
]};

gen(special_encoding, {J, E}) ->
{msg("~s", [J]), [
{"Encode", ?_assertEqual(J, enc(E))}
]};

gen(error, J) ->
{msg("Error: ~s", [J]), [
?_assertThrow({error, _}, dec(J))
Expand Down Expand Up @@ -53,6 +59,11 @@ cases(ok) ->
}
];

cases(special_encoding) ->
[
{<<"{\"123\":\"foo\"}">>, {[{123, <<"foo">>}]}}
];

cases(error) ->
[
<<"[{}">>,
Expand Down
3 changes: 0 additions & 3 deletions test/jiffy_12_error_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ enc_invalid_object_member_key_test_() ->
E1 = {1, true},
{"invalid_object_member_key", [
{"Bad string", enc_error(Type, <<143>>, {[{<<143>>, true}]})},
{"Basic", enc_error(Type, 1, {[{1, true}]})},
{"Basic", enc_error(Type, [1], {[{[1], true}]})},
{"Basic", enc_error(Type, {[{foo,bar}]}, {[{{[{foo,bar}]}, true}]})},
{"Second", enc_error(Type, 1, {[{bar, baz}, E1]})},
{"Nested", enc_error(Type, 1, {[{bar,{[E1]}}]})},
{"Nested", enc_error(Type, 1, {[{bar,{[{baz, 1}, E1]}}]})},
{"In List", enc_error(Type, 1, [{[E1]}])},
{"In List", enc_error(Type, 1, [{[{bang, true}, E1]}])}
]}.

Expand Down