File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,6 +109,11 @@ bool topic_filter::matches(const string& topic) const
109109{
110110 auto n = fields_.size ();
111111
112+ // Edge case of topic_filter("")
113+ if (n == 0 ) {
114+ return false ;
115+ }
116+
112117 auto topic_fields = topic::split (topic);
113118 auto nt = topic_fields.size ();
114119
@@ -126,7 +131,7 @@ bool topic_filter::matches(const string& topic) const
126131 // MQTT v5 Spec, Section 4.7.2:
127132 // https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901246
128133
129- if (n > 0 && is_wildcard (fields_[0 ]) && nt > 0 && topic_fields[0 ].size () > 0 &&
134+ if (is_wildcard (fields_[0 ]) && nt > 0 && topic_fields[0 ].size () > 0 &&
130135 topic_fields[0 ][0 ] == ' $' ) {
131136 return false ;
132137 }
Original file line number Diff line number Diff line change @@ -273,5 +273,8 @@ TEST_CASE("topic matches", "[topic_filter]")
273273 REQUIRE (!topic_filter{" #" }.matches (" $SYS/bar" ));
274274 REQUIRE (!topic_filter{" $BOB/bar" }.matches (" $SYS/bar" ));
275275 REQUIRE (!topic_filter{" +/bar" }.matches (" $SYS/bar" ));
276+ REQUIRE (!topic_filter{" " }.matches (" foo" ));
277+ REQUIRE (!topic_filter{" " }.matches (" foo/bar" ));
278+ REQUIRE (!topic_filter{" foo/bar" }.matches (" " ));
276279 }
277280}
You can’t perform that action at this time.
0 commit comments