This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 4ad7ef88d60 [fix][broker] Fix regex matching of namespace name which 
might contain a regex char (#25136)
4ad7ef88d60 is described below

commit 4ad7ef88d60c134f69a1dc19a2e1bb7245771a87
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 3247ac1a037..d6cb8db120b 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
@@ -115,4 +115,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);
+    }
 }

Reply via email to