From b1bf7698aa476e96801b95ecb5d95f9d71230abc Mon Sep 17 00:00:00 2001 From: Philip Schill Date: Fri, 29 Jan 2021 17:37:47 +0100 Subject: [PATCH] The topic filter comparer now checks for e.g. "foo/" matching "foo/#". --- Source/MQTTnet/Server/MqttTopicFilterComparer.cs | 7 +++++++ Tests/MQTTnet.Core.Tests/TopicFilterComparer_Tests.cs | 6 ++++++ 2 files changed, 13 insertions(+) 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() {