From 8103113cfb219868df746f1d13f5c765f3029987 Mon Sep 17 00:00:00 2001 From: erobot Date: Fri, 25 Nov 2022 18:10:14 +0800 Subject: [PATCH] Fix NamedEntity::checkName regression --- lib/NamedEntity.cc | 3 ++- tests/NamespaceNameTest.cc | 7 ++++--- tests/TopicNameTest.cc | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/NamedEntity.cc b/lib/NamedEntity.cc index 484c8b1f..a920c496 100644 --- a/lib/NamedEntity.cc +++ b/lib/NamedEntity.cc @@ -22,7 +22,7 @@ /** * Allowed characters for property, namespace, cluster and topic names are - * alphanumeric (a-zA-Z_0-9) and these special chars -=:. + * alphanumeric (a-zA-Z0-9) and these special chars _-=:. * @param name * @return */ @@ -33,6 +33,7 @@ bool NamedEntity::checkName(const std::string& name) { } switch (c) { + case '_': case '-': case '=': case ':': diff --git a/tests/NamespaceNameTest.cc b/tests/NamespaceNameTest.cc index 132506ea..f8fcfc72 100644 --- a/tests/NamespaceNameTest.cc +++ b/tests/NamespaceNameTest.cc @@ -44,9 +44,10 @@ TEST(NamespaceNameTest, testNamespaceNameV2) { } TEST(NamespaceNameTest, testNamespaceNameLegalCharacters) { - std::shared_ptr nn1 = NamespaceName::get("cluster-1:=.", "namespace-1:=."); - ASSERT_EQ("cluster-1:=.", nn1->getProperty()); + std::shared_ptr nn1 = NamespaceName::get("cluster-1:=._", "namespace-1:=._"); + ASSERT_TRUE(nn1); + ASSERT_EQ("cluster-1:=._", nn1->getProperty()); ASSERT_TRUE(nn1->getCluster().empty()); - ASSERT_EQ("namespace-1:=.", nn1->getLocalName()); + ASSERT_EQ("namespace-1:=._", nn1->getLocalName()); ASSERT_TRUE(nn1->isV2()); } diff --git a/tests/TopicNameTest.cc b/tests/TopicNameTest.cc index 44b3dc2d..41838f5d 100644 --- a/tests/TopicNameTest.cc +++ b/tests/TopicNameTest.cc @@ -143,12 +143,13 @@ TEST(TopicNameTest, testIllegalCharacters) { } TEST(TopicNameTest, testLegalNonAlphaCharacters) { - std::shared_ptr topicName = TopicName::get("persistent://cluster-1:=./namespace-1:=./topic"); + std::shared_ptr topicName = + TopicName::get("persistent://cluster-1:=._/namespace-1:=._/topic_"); ASSERT_TRUE(topicName); - ASSERT_EQ("cluster-1:=.", topicName->getProperty()); - ASSERT_EQ("namespace-1:=.", topicName->getNamespacePortion()); + ASSERT_EQ("cluster-1:=._", topicName->getProperty()); + ASSERT_EQ("namespace-1:=._", topicName->getNamespacePortion()); ASSERT_EQ("persistent", topicName->getDomain()); - ASSERT_EQ("topic", topicName->getLocalName()); + ASSERT_EQ("topic_", topicName->getLocalName()); } TEST(TopicNameTest, testIllegalUrl) {