This is an automated email from the ASF dual-hosted git repository.
zhaocong pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new dbbb37d36c9 [fix][broker] Fix regex matching of namespace name which
might contain a regex char (#25136)
dbbb37d36c9 is described below
commit dbbb37d36c9aa4804c4c631f32bbc70c21b0299a
Author: Lari Hotari <[email protected]>
AuthorDate: Tue Jan 13 14:59:33 2026 +0200
[fix][broker] Fix regex matching of namespace name which might contain a
regex char (#25136)
(cherry picked from commit 1fcdf8bb9a97fbc4c0db78c4aa8df2b1fae02a65)
---
.../org/apache/pulsar/broker/resources/TopicResources.java | 4 ++--
.../apache/pulsar/broker/resources/TopicResourcesTest.java | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/TopicResources.java
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/TopicResources.java
index 8ce4e5c8e20..de7596a7638 100644
---
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/TopicResources.java
+++
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/TopicResources.java
@@ -124,8 +124,8 @@ public class TopicResources {
}
Pattern namespaceNameToTopicNamePattern(NamespaceName namespaceName) {
- return Pattern.compile(
- MANAGED_LEDGER_PATH + "/(" + namespaceName + ")/(" +
TopicDomain.persistent + ")/(" + "[^/]+)");
+ return Pattern.compile(MANAGED_LEDGER_PATH + "/(" +
Pattern.quote(namespaceName.toString()) + ")/("
+ + TopicDomain.persistent + ")/(" + "[^/]+)");
}
public void registerPersistentTopicListener(
diff --git
a/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/resources/TopicResourcesTest.java
b/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/resources/TopicResourcesTest.java
index 07a4ae195c8..48092e2a830 100644
---
a/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/resources/TopicResourcesTest.java
+++
b/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/resources/TopicResourcesTest.java
@@ -123,4 +123,15 @@ public class TopicResourcesTest {
verify(listener).accept("persistent://tenant/namespace/topic:test",
NotificationType.Created);
}
+ @Test
+ public void testNamespaceContainsDotsShouldntMatchAny() {
+ BiConsumer<String, NotificationType> listener = mock(BiConsumer.class);
+
topicResources.registerPersistentTopicListener(NamespaceName.get("tenant/name.pace"),
listener);
+ topicResources.handleNotification(new
Notification(NotificationType.Created,
+ "/managed-ledgers/tenant/namespace/persistent/topic"));
+ verifyNoInteractions(listener);
+ topicResources.handleNotification(new
Notification(NotificationType.Created,
+ "/managed-ledgers/tenant/name.pace/persistent/topic"));
+ verify(listener).accept("persistent://tenant/name.pace/topic",
NotificationType.Created);
+ }
}