diff --git a/apps/emqx_rule_engine/src/emqx_rule_funcs.erl b/apps/emqx_rule_engine/src/emqx_rule_funcs.erl index 7354a217f..55917f751 100644 --- a/apps/emqx_rule_engine/src/emqx_rule_funcs.erl +++ b/apps/emqx_rule_engine/src/emqx_rule_funcs.erl @@ -706,52 +706,10 @@ map_get(Key, Map) -> map_get(Key, Map, undefined). map_get(Key, Map, Default) -> - case maps:find(Key, Map) of - {ok, Val} -> Val; - error when is_atom(Key) -> - %% the map may have an equivalent binary-form key - BinKey = emqx_rule_utils:bin(Key), - case maps:find(BinKey, Map) of - {ok, Val} -> Val; - error -> Default - end; - error when is_binary(Key) -> - try %% the map may have an equivalent atom-form key - AtomKey = list_to_existing_atom(binary_to_list(Key)), - case maps:find(AtomKey, Map) of - {ok, Val} -> Val; - error -> Default - end - catch error:badarg -> - Default - end; - error -> - Default - end. + emqx_rule_maps:nested_get(map_path(Key), Map, Default). map_put(Key, Val, Map) -> - case maps:find(Key, Map) of - {ok, _} -> maps:put(Key, Val, Map); - error when is_atom(Key) -> - %% the map may have an equivalent binary-form key - BinKey = emqx_rule_utils:bin(Key), - case maps:find(BinKey, Map) of - {ok, _} -> maps:put(BinKey, Val, Map); - error -> maps:put(Key, Val, Map) - end; - error when is_binary(Key) -> - try %% the map may have an equivalent atom-form key - AtomKey = list_to_existing_atom(binary_to_list(Key)), - case maps:find(AtomKey, Map) of - {ok, _} -> maps:put(AtomKey, Val, Map); - error -> maps:put(Key, Val, Map) - end - catch error:badarg -> - maps:put(Key, Val, Map) - end; - error -> - maps:put(Key, Val, Map) - end. + emqx_rule_maps:nested_put(map_path(Key), Val, Map). mget(Key, Map) -> mget(Key, Map, undefined).