Add validation for topics before publishing.

This commit is contained in:
Christian Kratky
2019-03-22 20:37:14 +01:00
parent 673fc5e20c
commit 7c3d88f62d
9 changed files with 84 additions and 9 deletions
@@ -0,0 +1,25 @@
using MQTTnet.Exceptions;
namespace MQTTnet.Protocol
{
public static class MqttTopicValidator
{
public static void ThrowIfInvalid(string topic)
{
if (string.IsNullOrEmpty(topic))
{
throw new MqttProtocolViolationException("Topic should not be empty.");
}
if (topic.Contains("+"))
{
throw new MqttProtocolViolationException("The character '+' is not allowed in topics.");
}
if (topic.Contains("#"))
{
throw new MqttProtocolViolationException("The character '#' is not allowed in topics.");
}
}
}
}