diff --git a/Source/MQTTnet/Server/MqttTopicFilterComparer.cs b/Source/MQTTnet/Server/MqttTopicFilterComparer.cs index 4ba614d..5b104b4 100644 --- a/Source/MQTTnet/Server/MqttTopicFilterComparer.cs +++ b/Source/MQTTnet/Server/MqttTopicFilterComparer.cs @@ -31,6 +31,13 @@ namespace MQTTnet.Server { return true; } + // Check for e.g. foo/ matching foo/# + if (sPos == sLen - 2 + && filter[sPos] == LevelSeparator + && filter[sPos + 1] == MultiLevelWildcard) + { + return true; + } } sPos++; diff --git a/Tests/MQTTnet.Core.Tests/TopicFilterComparer_Tests.cs b/Tests/MQTTnet.Core.Tests/TopicFilterComparer_Tests.cs index 35e8504..b1de7c8 100644 --- a/Tests/MQTTnet.Core.Tests/TopicFilterComparer_Tests.cs +++ b/Tests/MQTTnet.Core.Tests/TopicFilterComparer_Tests.cs @@ -54,6 +54,12 @@ namespace MQTTnet.Tests CompareAndAssert("A/B/C/D", "A/C/#", false); } + [TestMethod] + public void TopicFilterComparer_EndMultipleLevelsWildcardMatchEmptyLevel() + { + CompareAndAssert("A/", "A/#", true); + } + [TestMethod] public void TopicFilterComparer_AllLevelsWildcardMatch() {