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())).
|
||||
match(Topic) when is_binary(Topic) ->
|
||||
Words = emqx_topic:words(Topic),
|
||||
false = emqx_topic:wildcard(Words), % assert
|
||||
do_match(Words).
|
||||
case emqx_topic:wildcard(Words) of
|
||||
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?
|
||||
-spec(empty() -> boolean()).
|
||||
|
|
|
@ -81,6 +81,16 @@ t_match(_) ->
|
|||
end),
|
||||
?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(_) ->
|
||||
Matched = [<<"#">>, <<"+/#">>, <<"+/+/#">>],
|
||||
trans(fun() ->
|
||||
|
|
Loading…
Reference in New Issue