hbmqtt icon indicating copy to clipboard operation
hbmqtt copied to clipboard

Single-level wildcards match more than one level

Open mtappler opened this issue 8 years ago • 1 comments

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.

mtappler avatar Jun 13 '16 06:06 mtappler

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

tony2nite avatar Oct 04 '16 08:10 tony2nite