hbmqtt
hbmqtt copied to clipboard
Single-level wildcards match more than one level
This issue is related to issue #41.
There is another problem, which existed before and which persists with the fix of issue #41. The single-level wildcards denoted by + should not match more than one level, but the replacement-regex allows matching strings as well as level-separators /
, so I guess replace('+', '[/\$\s\w\d]+')
should be changed to something like replace('+', '[^/\$\s\w\d]+')
, i.e. it should only match characters unequal to a /
.
I should note that I did not evaluate this fix thoroughly either. I just checked with some string and did not test special cases like zero length topic names.
However, by doing so, issue #41 would still persist I think if wildcards are used. Since the regex would partially match, by subscribing to a/+/b
, one would also receive messages published for a/something/b/anotherthing
.
In addition to issues with a/+/b
, I think with the current logic this also won't publish correctly a/+/b/+/c
(at least for me). Seems the parsing of wildcard needs to be more sophisticated to match a variety of subscription combinations:
+/b/c/d
a/+/c/d
a/+/+/d
+/+/+/+
+/b/c/#
Rather than a single Regex maybe needs a version of something like this https://github.com/RangerMauve/mqtt-regex