From c013a59d166c4642a1578623276653514e5b4ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chmielowski?= Date: Mon, 15 Jul 2024 21:29:17 +0200 Subject: [PATCH] Restore args conversion of {"k":"v"} to tuple lists in mod_http_api Switching to json compatible output did broke this, which caused issues in for example create_rooms_with_opts command. --- src/mod_http_api.erl | 8 ++++++++ test/commands_tests.erl | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mod_http_api.erl b/src/mod_http_api.erl index 1e7e44a33..ac122b5dc 100644 --- a/src/mod_http_api.erl +++ b/src/mod_http_api.erl @@ -332,6 +332,14 @@ format_arg({Elements}, ({Val}) when is_list(Val) -> format_arg({Val}, Tuple) end, Elements); +format_arg(Map, + {list, {_ElementDefName, {tuple, [{_Tuple1N, Tuple1S}, {_Tuple2N, Tuple2S}]}}}) + when is_map(Map) andalso + (Tuple1S == binary orelse Tuple1S == string) -> + maps:fold( + fun(K, V, Acc) -> + [{format_arg(K, Tuple1S), format_arg(V, Tuple2S)} | Acc] + end, [], Map); format_arg(Elements, {list, {_ElementDefName, {list, _} = ElementDefFormat}}) when is_list(Elements) -> diff --git a/test/commands_tests.erl b/test/commands_tests.erl index 4081a9e07..9cc23dee5 100644 --- a/test/commands_tests.erl +++ b/test/commands_tests.erl @@ -47,7 +47,8 @@ single_cases() -> single_test(http_restuple), single_test(http_list), single_test(http_tuple), - single_test(http_list_tuple)]}. + single_test(http_list_tuple), + single_test(http_list_tuple_map)]}. setup(_Config) -> M = <<"mod_example">>, @@ -139,6 +140,13 @@ http_list_tuple(Config) -> ?match(LTB, query(Config, "command_test_list_tuple", #{arg_list => LTA})), ?match(LTB, query(Config, "command_test_list_tuple", #{arg_list => LTB})). +http_list_tuple_map(Config) -> + LTA = #{<<"one">> => <<"uno">>, <<"dos">> => <<"two">>, <<"three">> => <<"tres">>}, + LTB = lists:sort([#{<<"element1">> => <<"one">>, <<"element2">> => <<"uno">>}, + #{<<"element1">> => <<"dos">>, <<"element2">> => <<"two">>}, + #{<<"element1">> => <<"three">>, <<"element2">> => <<"tres">>}]), + ?match(LTB, lists:sort(query(Config, "command_test_list_tuple", #{arg_list => LTA}))). + %%%================================== %%%% internal functions