Merge pull request #1418 from HJianBo/develop

Fix issue #1398
This commit is contained in:
Feng Lee 2017-12-27 15:18:16 +08:00 committed by GitHub
commit d8f78c885d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -61,18 +61,18 @@ wildcard([_H|T]) ->
-spec(match(Name, Filter) -> boolean() when
Name :: topic() | words(),
Filter :: topic() | words()).
match(<<$$, _/binary>>, <<$+, _/binary>>) ->
false;
match(<<$$, _/binary>>, <<$#, _/binary>>) ->
false;
match(Name, Filter) when is_binary(Name) and is_binary(Filter) ->
match(words(Name), words(Filter));
match([], []) ->
true;
match([H|T1], [H|T2]) ->
match(T1, T2);
match([<<$$, _/binary>>|_], ['+'|_]) ->
false;
match([_H|T1], ['+'|T2]) ->
match(T1, T2);
match([<<$$, _/binary>>|_], ['#']) ->
false;
match(_, ['#']) ->
true;
match([_H1|_], [_H2|_]) ->

View File

@ -73,10 +73,10 @@ t_match2(_) ->
t_match3(_) ->
true = match(<<"device/60019423a83c/fw">>, <<"device/60019423a83c/#">>),
false = match(<<"device/60019423a83c/$fw">>, <<"device/60019423a83c/#">>),
true = match(<<"device/60019423a83c/$fw">>, <<"device/60019423a83c/#">>),
true = match(<<"device/60019423a83c/$fw/fw">>, <<"device/60019423a83c/$fw/#">>),
true = match(<<"device/60019423a83c/fw/checksum">>, <<"device/60019423a83c/#">>),
false = match(<<"device/60019423a83c/$fw/checksum">>, <<"device/60019423a83c/#">>),
true = match(<<"device/60019423a83c/$fw/checksum">>, <<"device/60019423a83c/#">>),
true = match(<<"device/60019423a83c/dust/type">>, <<"device/60019423a83c/#">>).
t_sigle_level_match(_) ->
@ -86,7 +86,9 @@ t_sigle_level_match(_) ->
true = match(<<"sport/">>, <<"sport/+">>),
true = match(<<"/finance">>, <<"+/+">>),
true = match(<<"/finance">>, <<"/+">>),
false = match(<<"/finance">>, <<"+">>).
false = match(<<"/finance">>, <<"+">>),
true = match(<<"/devices/$dev1">>, <<"/devices/+">>),
true = match(<<"/devices/$dev1/online">>, <<"/devices/+/online">>).
t_sys_match(_) ->
true = match(<<"$SYS/broker/clients/testclient">>, <<"$SYS/#">>),
@ -95,9 +97,11 @@ t_sys_match(_) ->
false = match(<<"$SYS/broker">>, <<"#">>).
't_#_match'(_) ->
true = match(<<"a/b/c">>, <<"#">>),
true = match(<<"a/b/c">>, <<"+/#">>),
false = match(<<"$SYS/brokers">>, <<"#">>).
true = match(<<"a/b/c">>, <<"#">>),
true = match(<<"a/b/c">>, <<"+/#">>),
false = match(<<"$SYS/brokers">>, <<"#">>),
true = match(<<"a/b/$c">>, <<"a/b/#">>),
true = match(<<"a/b/$c">>, <<"a/#">>).
t_match_perf(_) ->
true = match(<<"a/b/ccc">>, <<"a/#">>),