Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 20 additions & 5 deletions src/hex_tarball.erl
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ characters_to_list(Binary) ->
normalize_metadata(Metadata1) ->
Metadata2 = maybe_update_with(<<"requirements">>, fun normalize_requirements/1, Metadata1),
Metadata3 = maybe_update_with(<<"links">>, fun try_into_map/1, Metadata2),
Metadata4 = maybe_update_with(<<"extra">>, fun try_into_map/1, Metadata3),
Metadata4 = maybe_update_with(<<"extra">>, fun try_into_nested_map/1, Metadata3),
guess_build_tools(Metadata4).

%% @private
Expand Down Expand Up @@ -665,14 +665,29 @@ try_into_map(List) ->

%% @private
try_into_map(Fun, Input) ->
case
is_list(Input) andalso
lists:all(fun(E) -> is_tuple(E) andalso (tuple_size(E) == 2) end, Input)
of
case has_map_shape(Input) of
true -> maps:from_list(lists:map(Fun, Input));
false -> Input
end.

%% @private
try_into_nested_map(List) ->
try_into_nested_map(fun(X) -> X end, List).

%% @private
try_into_nested_map(Fun, Input) ->
case has_map_shape(Input) of
true -> maps:from_list(lists:map(fun({Key, Value}) ->
Fun({Key, try_into_nested_map(Fun, Value)})
end, Input));
false -> Input
end.

%% @private
has_map_shape(Input) ->
is_list(Input) andalso
lists:all(fun(E) -> is_tuple(E) andalso (tuple_size(E) == 2) end, Input).

%% @private
encode_base16(Binary) ->
<<X:256/big-unsigned-integer>> = Binary,
Expand Down
6 changes: 4 additions & 2 deletions test/hex_tarball_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,19 @@ memory_test(_Config) ->
<<"name">> => <<"foo">>,
<<"version">> => <<"1.0.0">>,
<<"maintainers">> => [<<"José">>],
<<"build_tool">> => <<"rebar3">>
<<"build_tool">> => <<"rebar3">>,
<<"extra">> => [{<<"foo">>, [{<<"bar">>, <<"baz">>}]}]
},
Contents = [{"src/foo.erl", <<"-module(foo).">>}],
{ok, #{tarball := Tarball, inner_checksum := InnerChecksum, outer_checksum := OuterChecksum}} = hex_tarball:create(
Metadata, Contents
),
Metadata1 = maps:put(<<"extra">>, #{<<"foo">> => #{<<"bar">> => <<"baz">>}}, Metadata),
{ok, #{
inner_checksum := InnerChecksum,
outer_checksum := OuterChecksum,
contents := Contents,
metadata := Metadata
metadata := Metadata1
}} = hex_tarball:unpack(Tarball, memory),
ok.

Expand Down