eclipse-paho / eclipse-paho/paho.mqtt.java

Mqtt topic filtering does not conform to spec: filter foo/+/bar/# won't catch messages published to foo/something/bar

Open
#918 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

In the case that there is a single level wildcard somewhere in the topic the fixes provided by https://github.com/eclipse/paho.mqtt.java/issues/418 won't work

For example when i subscribe to foo/+/bar/# and publish on foo/something/bar

-> if (topicName.charAt(topicPos - 1) == '/' && topicFilter.charAt(filterPos) == '#')
this returns false, because the topicFilter at filterPos is / and not #

-> if (topicFilter.length() - filterPos > 1 && topicFilter.substring(filterPos, filterPos + 2).equals("/#"))
returns false, because topicFilter length - filterPos is exactly 1

-> if ((topicFilter.length() - topicName.length()) == 2 && topicFilter.substring(topicFilter.length() - 2, topicFilter.length()).equals("/#"))
returns false, because topicFilter length - topicName length is negative the length of the word that replaces the single level wildcard plus 3 ( 1 for the single level wildcard and 2 for the /#)

- [ ] Bug exists Release Version 1.2.5 ( Master Branch)
- [ ] Bug exists in MQTTv3 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
- [ ] Bug exists in MQTTv5 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.