Przeglądaj źródła

fix(retainer): Handle zero-length topic levels

ieQu1 3 lat temu
rodzic
commit
8ff9a03df3

+ 2 - 2
apps/emqx_retainer/src/emqx_retainer_index.erl

@@ -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]).
 

+ 8 - 0
apps/emqx_retainer/test/emqx_retainer_index_SUITE.erl

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