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:
Andrew Mayorov 2023-12-04 12:59:16 +03:00
parent b5c485cd55
commit 92c4b29a4c
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
2 changed files with 9 additions and 5 deletions

View File

@ -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

View File

@ -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">>,