Merge pull request #9633 from zhongwencool/fix-json-fmt

fix: bad best fmt json []
This commit is contained in:
zhongwencool 2022-12-30 09:08:13 +08:00 committed by GitHub
commit f92b1fb8f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -3,7 +3,7 @@
{id, "emqx"}, {id, "emqx"},
{description, "EMQX Core"}, {description, "EMQX Core"},
% strict semver, bump manually! % strict semver, bump manually!
{vsn, "5.0.13"}, {vsn, "5.0.14"},
{modules, []}, {modules, []},
{registered, []}, {registered, []},
{applications, [ {applications, [

View File

@ -221,7 +221,7 @@ best_effort_json_obj(Map, Config) ->
end. end.
json([], _) -> json([], _) ->
"[]"; "";
json(<<"">>, _) -> json(<<"">>, _) ->
"\"\""; "\"\"";
json(A, _) when is_atom(A) -> atom_to_binary(A, utf8); json(A, _) when is_atom(A) -> atom_to_binary(A, utf8);
@ -376,4 +376,19 @@ p_config() ->
] ]
). ).
best_effort_json_test() ->
?assertEqual(
<<"{}">>,
emqx_logger_jsonfmt:best_effort_json([])
),
?assertEqual(
<<"{\n \"key\": []\n}">>,
emqx_logger_jsonfmt:best_effort_json(#{key => []})
),
?assertEqual(
<<"[\n {\n \"key\": []\n }\n]">>,
emqx_logger_jsonfmt:best_effort_json([#{key => []}])
),
ok.
-endif. -endif.