Fix unit tests for topic templates (#1976)

This commit is contained in:
simonthum
2024-04-26 18:35:27 +02:00
committed by GitHub
parent 2410d7b4c1
commit 1aa91e3828
2 changed files with 137 additions and 14 deletions
@@ -152,17 +152,28 @@ namespace MQTTnet.Extensions.TopicTemplate
}
}
return a.Substring(0, maxIndex);
return a.Substring(0, maxIndex+1);
}
foreach (var topic in from template in templates select template.Template)
foreach (string topic in from template in templates select template.Template)
{
root = root == null ? topic : CommonPrefix(root, topic);
}
root = root ?? "";
if (string.IsNullOrEmpty(root))
return new MqttTopicTemplate(MqttTopicFilterComparer.MultiLevelWildcard.ToString());
return new MqttTopicTemplate(root.Substring(0, root.LastIndexOf('/')));
if (root.Contains(MqttTopicFilterComparer.LevelSeparator) &&
!root.EndsWith(MqttTopicFilterComparer.LevelSeparator.ToString()) &&
!root.EndsWith("}"))
{
root = root.Substring(0, root.LastIndexOf(MqttTopicFilterComparer.LevelSeparator)+1);
}
if (root.EndsWith(MqttTopicFilterComparer.LevelSeparator.ToString()))
root += MqttTopicFilterComparer.SingleLevelWildcard;
return new MqttTopicTemplate(root);
}
public override int GetHashCode()