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
4 changes: 3 additions & 1 deletion src/connection/mc_connection_man.erl
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ normalize_value({K, V}) when is_atom(K); is_binary(K) ->
normalize_value(V) when is_map(V) ->
%% Recursively normalize nested maps
normalize_map_values(V);
normalize_value([]) ->
[];
normalize_value(V) when is_list(V) ->
%% Check if it's a proplist or just a list
%% Convert proplists to maps; regular lists keep BSON array semantics.
case is_proplist(V) of
true -> maps:from_list([{ensure_binary(K), normalize_value(Val)} || {K, Val} <- V]);
false -> V %% Regular list, leave as-is
Expand Down
18 changes: 17 additions & 1 deletion test/tuple_normalization_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
test_mixed_nested_structures/1,
test_already_normalized_map/1,
test_atom_keys_to_binary/1,
test_empty_list_unchanged/1,
test_regular_list_unchanged/1,
test_deep_nesting/1
]).
Expand All @@ -30,6 +31,7 @@ all() ->
test_mixed_nested_structures,
test_already_normalized_map,
test_atom_keys_to_binary,
test_empty_list_unchanged,
test_regular_list_unchanged,
test_deep_nesting
].
Expand Down Expand Up @@ -146,6 +148,20 @@ test_atom_keys_to_binary(_Config) ->
Result = normalize_map_values(Input),
?assertEqual(Expected, Result).

test_empty_list_unchanged(_Config) ->
%% Empty lists should remain arrays, not be coerced into empty maps
Input = #{
<<"findAndModify">> => <<"devices">>,
<<"update">> => #{
<<"$set">> => #{
<<"test_3">> => []
}
}
},
Expected = Input,
Result = normalize_map_values(Input),
?assertEqual(Expected, Result).

test_regular_list_unchanged(_Config) ->
%% Regular lists (not proplists) should remain unchanged
Input = #{
Expand All @@ -172,4 +188,4 @@ test_deep_nesting(_Config) ->
}
},
Result = normalize_map_values(Input),
?assertEqual(Expected, Result).
?assertEqual(Expected, Result).
Loading