Skip to content

Commit 78b528b

Browse files
chuenchen309auvipy
andauthored
Stop the topic '*' wildcard from matching across dots (#2568)
TopicExchange documents '*' as any single word, but compiled it to '.*?[^\.]', whose leading '.*?' also matches dots. Only the final character was constrained, so 'a.*.c' matched 'a.b.x.c' and every virtual transport delivered messages to queues that never bound them. Compile '*' to a single dot-free word instead. '#' is unchanged. Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com>
1 parent e592de0 commit 78b528b

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

kombu/transport/virtual/exchange.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class TopicExchange(ExchangeType):
8686
type = 'topic'
8787

8888
#: map of wildcard to regex conversions
89-
wildcards = {'*': r'.*?[^\.]',
89+
wildcards = {'*': r'[^\.]+',
9090
'#': r'.*?'}
9191

9292
#: compiled regex cache

t/unit/transport/virtual/test_exchange.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def test_prepare_bind(self):
8484
('eFoo', 'stock.europe.OSE', None, {'rFoo'}),
8585
('eFoo', 'stockxeuropexOSE', None, set()),
8686
('eFoo', 'candy.schleckpulver.snap_crackle', None, set()),
87+
# '*' is a single word: only 'stock.#' may match a longer key.
88+
('eFoo', 'stock.us.nasdaq.tech', None, {'rFoo'}),
8789
])
8890
def test_lookup(self, exchange, routing_key, default, expected):
8991
assert self.e.lookup(

0 commit comments

Comments
 (0)