Skip to content

Commit

Permalink
Fixed matching + and # containing topics
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Aug 3, 2024
1 parent b8c68c8 commit 808b32d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions broker/src/main/java/io/moquette/broker/subscriptions/CTrie.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,21 @@ private List<Subscription> recursiveMatch(Topic topicName, INode inode, int dept
if (action == NavigationAction.STOP) {
return Collections.emptyList();
}
Topic remainingTopic = (ROOT.equals(cnode.getToken())) ? topicName : topicName.exceptHeadToken();
final boolean isRoot = ROOT.equals(cnode.getToken());
final boolean isSingle = Token.SINGLE.equals(cnode.getToken());
final boolean isMulti = Token.MULTI.equals(cnode.getToken());

Topic remainingTopic = isRoot
? topicName
: (isSingle || isMulti)
? topicName.exceptFullHeadToken()
: topicName.exceptHeadToken();
List<Subscription> subscriptions = new ArrayList<>();

// We should only consider the maximum three children children of
// type #, + or exact match
Optional<INode> subInode = cnode.childOf(Token.MULTI);
if (subInode.isPresent()) {
Topic remainingRealTopic = (ROOT.equals(cnode.getToken())) ? topicName : topicName.exceptFullHeadToken();
subscriptions.addAll(recursiveMatch(remainingTopic, subInode.get(), depth + 1));
}
subInode = cnode.childOf(Token.SINGLE);
Expand Down

0 comments on commit 808b32d

Please sign in to comment.