Merge pull request #10801 from JimMoen/fix-topic-lookup-percent-decode
fix: lookup topic without force percent decode
This commit is contained in:
commit
cc2bb87b82
|
@ -139,9 +139,9 @@ lookup(#{topic := Topic}) ->
|
|||
%%%==============================================================================================
|
||||
%% internal
|
||||
generate_topic(Params = #{<<"topic">> := Topic}) ->
|
||||
Params#{<<"topic">> => uri_string:percent_decode(Topic)};
|
||||
Params#{<<"topic">> => Topic};
|
||||
generate_topic(Params = #{topic := Topic}) ->
|
||||
Params#{topic => uri_string:percent_decode(Topic)};
|
||||
Params#{topic => Topic};
|
||||
generate_topic(Params) ->
|
||||
Params.
|
||||
|
||||
|
|
|
@ -92,4 +92,35 @@ t_nodes_api(Config) ->
|
|||
#{<<"topic">> := Topic, <<"node">> := Node2}
|
||||
] = emqx_utils_json:decode(RouteResponse, [return_maps]),
|
||||
|
||||
?assertEqual(lists:usort([Node, atom_to_binary(Slave)]), lists:usort([Node1, Node2])).
|
||||
?assertEqual(lists:usort([Node, atom_to_binary(Slave)]), lists:usort([Node1, Node2])),
|
||||
|
||||
ok = emqtt:stop(Client).
|
||||
|
||||
t_percent_topics(_Config) ->
|
||||
Node = atom_to_binary(node(), utf8),
|
||||
Topic = <<"test_%%1">>,
|
||||
{ok, Client} = emqtt:start_link(#{
|
||||
username => <<"routes_username">>, clientid => <<"routes_cid">>
|
||||
}),
|
||||
{ok, _} = emqtt:connect(Client),
|
||||
{ok, _, _} = emqtt:subscribe(Client, Topic),
|
||||
|
||||
%% exact match with percent encoded topic
|
||||
Path = emqx_mgmt_api_test_util:api_path(["topics"]),
|
||||
QS = uri_string:compose_query([
|
||||
{"topic", Topic},
|
||||
{"node", atom_to_list(node())}
|
||||
]),
|
||||
Headers = emqx_mgmt_api_test_util:auth_header_(),
|
||||
{ok, MatchResponse} = emqx_mgmt_api_test_util:request_api(get, Path, QS, Headers),
|
||||
MatchData = emqx_utils_json:decode(MatchResponse, [return_maps]),
|
||||
?assertMatch(
|
||||
#{<<"count">> := 1, <<"page">> := 1, <<"limit">> := 100},
|
||||
maps:get(<<"meta">>, MatchData)
|
||||
),
|
||||
?assertMatch(
|
||||
[#{<<"topic">> := Topic, <<"node">> := Node}],
|
||||
maps:get(<<"data">>, MatchData)
|
||||
),
|
||||
|
||||
ok = emqtt:stop(Client).
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Avoid duplicated percent decode the topic name in API `/topics/{topic}` and `/topics`.
|
Loading…
Reference in New Issue