feat(topic): match empty topic levels more loosely
So that the result of `emqx_topic:tokens/1` would be perfectly matchable with the result of `emqx_topic:words/1` of a topic filter with empty levels.
This commit is contained in:
parent
b5c485cd55
commit
92c4b29a4c
|
@ -91,13 +91,11 @@ match([H | T1], [H | T2]) ->
|
|||
match(T1, T2);
|
||||
match([_H | T1], ['+' | T2]) ->
|
||||
match(T1, T2);
|
||||
match([<<>> | T1], ['' | T2]) ->
|
||||
match(T1, T2);
|
||||
match(_, ['#']) ->
|
||||
true;
|
||||
match([_H1 | _], [_H2 | _]) ->
|
||||
false;
|
||||
match([_H1 | _], []) ->
|
||||
false;
|
||||
match([], [_H | _T2]) ->
|
||||
match(_, _) ->
|
||||
false.
|
||||
|
||||
-spec match_share(Name, Filter) -> boolean() when
|
||||
|
|
|
@ -115,6 +115,12 @@ t_sys_match(_) ->
|
|||
true = match(<<"a/b/$c">>, <<"a/b/#">>),
|
||||
true = match(<<"a/b/$c">>, <<"a/#">>).
|
||||
|
||||
t_match_tokens(_) ->
|
||||
true = match(emqx_topic:tokens(<<"a/b/c">>), words(<<"a/+/c">>)),
|
||||
true = match(emqx_topic:tokens(<<"a//c">>), words(<<"a/+/c">>)),
|
||||
false = match(emqx_topic:tokens(<<"a//c/">>), words(<<"a/+/c">>)),
|
||||
true = match(emqx_topic:tokens(<<"a//c/">>), words(<<"a/+/c/#">>)).
|
||||
|
||||
t_match_perf(_) ->
|
||||
true = match(<<"a/b/ccc">>, <<"a/#">>),
|
||||
Name = <<"/abkc/19383/192939/akakdkkdkak/xxxyyuya/akakak">>,
|
||||
|
|
Loading…
Reference in New Issue