fix(retainer): Handle zero-length topic levels

This commit is contained in:
ieQu1 2022-06-09 13:46:56 +02:00
parent bc96c9fda7
commit 8ff9a03df3
2 changed files with 10 additions and 2 deletions

View File

@ -176,11 +176,11 @@ condition([NIndex | OtherIndex], ['+' | OtherTokens], N, IndexMatch, OtherMatch)
condition(Index, ['+' | OtherTokens], N, IndexMatch, OtherMatch) ->
condition(Index, OtherTokens, N + 1, IndexMatch, ['_' | OtherMatch]);
condition([NIndex | OtherIndex], [Token | OtherTokens], N, IndexMatch, OtherMatch) when
NIndex =:= N, is_binary(Token)
NIndex =:= N, is_binary(Token) orelse Token =:= ''
->
condition(OtherIndex, OtherTokens, N + 1, [Token | IndexMatch], OtherMatch);
condition(Index, [Token | OtherTokens], N, IndexMatch, OtherMatch) when
is_binary(Token)
is_binary(Token) orelse Token =:= ''
->
condition(Index, OtherTokens, N + 1, IndexMatch, [Token | OtherMatch]).

View File

@ -193,6 +193,14 @@ t_condition_index(_Config) ->
[1],
[<<"a">>, '#']
)
),
?assertEqual(
{[1, 2, 3], {['', <<"saya">>, '_'], []}},
emqx_retainer_index:condition(
[1, 2, 3],
['', <<"saya">>, '+']
)
).
t_restore_topic(_Config) ->