This is an automated email from the ASF dual-hosted git repository.
xyz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new 96d8705 Fix NamedEntity::checkName regression (#127)
96d8705 is described below
commit 96d870527d2a078645c4866e9d75b3f3b97193ba
Author: TT <[email protected]>
AuthorDate: Mon Nov 28 11:16:52 2022 +0800
Fix NamedEntity::checkName regression (#127)
---
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 484c8b1..a920c49 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 132506e..f8fcfc7 100644
--- a/tests/NamespaceNameTest.cc
+++ b/tests/NamespaceNameTest.cc
@@ -44,9 +44,10 @@ TEST(NamespaceNameTest, testNamespaceNameV2) {
}
TEST(NamespaceNameTest, testNamespaceNameLegalCharacters) {
- std::shared_ptr<NamespaceName> nn1 = NamespaceName::get("cluster-1:=.",
"namespace-1:=.");
- ASSERT_EQ("cluster-1:=.", nn1->getProperty());
+ std::shared_ptr<NamespaceName> 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 44b3dc2..41838f5 100644
--- a/tests/TopicNameTest.cc
+++ b/tests/TopicNameTest.cc
@@ -143,12 +143,13 @@ TEST(TopicNameTest, testIllegalCharacters) {
}
TEST(TopicNameTest, testLegalNonAlphaCharacters) {
- std::shared_ptr<TopicName> topicName =
TopicName::get("persistent://cluster-1:=./namespace-1:=./topic");
+ std::shared_ptr<TopicName> 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) {