The MQTT device factory adds topic segments to the mapping context, e.g. foo/bar gives context.topic-0 set to foo.
This was failing if the the topic was starting with a /, e.g. /foo/bar.
This PR fixes the segmentation process, following the MQTT specification:
/foo, foo and foo/ are different
with a / prefix, context.topic-0 is always an empty string
with a / suffix, context.topic-last is always an empty string
foo/bar and foo//bar are equivalent, but foo/bar and foo/ /bar are different (and context.topic-1 will be a space character)
The MQTT device factory adds topic segments to the mapping context, e.g.
foo/bar
givescontext.topic-0
set tofoo
. This was failing if the the topic was starting with a/
, e.g./foo/bar
.This PR fixes the segmentation process, following the MQTT specification:
/foo
,foo
andfoo/
are different/
prefix,context.topic-0
is always an empty string/
suffix,context.topic-last
is always an empty stringfoo/bar
andfoo//bar
are equivalent, butfoo/bar
andfoo/ /bar
are different (andcontext.topic-1
will be a space character)