fix(rule): incorrect merge for map_get/2,3 and map_put/3
This commit is contained in:
parent
196fef0255
commit
e201484163
|
@ -706,52 +706,10 @@ map_get(Key, Map) ->
|
||||||
map_get(Key, Map, undefined).
|
map_get(Key, Map, undefined).
|
||||||
|
|
||||||
map_get(Key, Map, Default) ->
|
map_get(Key, Map, Default) ->
|
||||||
case maps:find(Key, Map) of
|
emqx_rule_maps:nested_get(map_path(Key), Map, Default).
|
||||||
{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.
|
|
||||||
|
|
||||||
map_put(Key, Val, Map) ->
|
map_put(Key, Val, Map) ->
|
||||||
case maps:find(Key, Map) of
|
emqx_rule_maps:nested_put(map_path(Key), Val, Map).
|
||||||
{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.
|
|
||||||
|
|
||||||
mget(Key, Map) ->
|
mget(Key, Map) ->
|
||||||
mget(Key, Map, undefined).
|
mget(Key, Map, undefined).
|
||||||
|
|
Loading…
Reference in New Issue