fix(emqx_trie): do not try to match wildcard topics
This commit is contained in:
parent
22e72cdd82
commit
eb946eb80c
|
@ -105,8 +105,19 @@ delete(Topic) when is_binary(Topic) ->
|
||||||
-spec(match(emqx_topic:topic()) -> list(emqx_topic:topic())).
|
-spec(match(emqx_topic:topic()) -> list(emqx_topic:topic())).
|
||||||
match(Topic) when is_binary(Topic) ->
|
match(Topic) when is_binary(Topic) ->
|
||||||
Words = emqx_topic:words(Topic),
|
Words = emqx_topic:words(Topic),
|
||||||
false = emqx_topic:wildcard(Words), % assert
|
case emqx_topic:wildcard(Words) of
|
||||||
do_match(Words).
|
true ->
|
||||||
|
%% In MQTT spec, clients are not allowed to
|
||||||
|
%% publish messages to a wildcard topic.
|
||||||
|
%% Here we refuse to match wildcard topic.
|
||||||
|
%%
|
||||||
|
%% NOTE: this does not imply emqx allows clients
|
||||||
|
%% publishing to wildcard topics.
|
||||||
|
%% Such clients will get disconnected.
|
||||||
|
[];
|
||||||
|
false ->
|
||||||
|
do_match(Words)
|
||||||
|
end.
|
||||||
|
|
||||||
%% @doc Is the trie empty?
|
%% @doc Is the trie empty?
|
||||||
-spec(empty() -> boolean()).
|
-spec(empty() -> boolean()).
|
||||||
|
|
|
@ -81,6 +81,16 @@ t_match(_) ->
|
||||||
end),
|
end),
|
||||||
?assertEqual(Machted, lists:sort(?TRIE:match(<<"sensor/1">>))).
|
?assertEqual(Machted, lists:sort(?TRIE:match(<<"sensor/1">>))).
|
||||||
|
|
||||||
|
t_match_invalid(_) ->
|
||||||
|
trans(fun() ->
|
||||||
|
?TRIE:insert(<<"sensor/1/metric/2">>),
|
||||||
|
?TRIE:insert(<<"sensor/+/#">>),
|
||||||
|
?TRIE:insert(<<"sensor/#">>)
|
||||||
|
end),
|
||||||
|
?assertEqual([], lists:sort(?TRIE:match(<<"sensor/+">>))),
|
||||||
|
?assertEqual([], lists:sort(?TRIE:match(<<"#">>))).
|
||||||
|
|
||||||
|
|
||||||
t_match2(_) ->
|
t_match2(_) ->
|
||||||
Matched = [<<"#">>, <<"+/#">>, <<"+/+/#">>],
|
Matched = [<<"#">>, <<"+/#">>, <<"+/+/#">>],
|
||||||
trans(fun() ->
|
trans(fun() ->
|
||||||
|
|
Loading…
Reference in New Issue