Skip to content

Commit 66ef6ac

Browse files
committed
make dispatcher match partial addreses when * is in the middle of them and force end to match. Fixes #180
1 parent ae1e5dd commit 66ef6ac

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

pythonosc/dispatcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ def handlers_for_address(
240240
matched = False
241241
for addr, handlers in self._map.items():
242242
if patterncompiled.match(addr) or (
243-
("*" in addr)
244-
and re.match(addr.replace("*", "[^/]*?/*"), address_pattern)
243+
"*" in addr
244+
and re.match(addr.replace("*", ".*?") + "$", address_pattern)
245245
):
246246
yield from handlers
247247
matched = True

pythonosc/test/test_dispatcher.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ def dummyhandler():
181181
with self.assertRaises(ValueError):
182182
self.dispatcher.unmap("/unmap/exception", handlerobj)
183183

184+
def test_handlers_for_address_wildcard_no_partial_match(self):
185+
self.dispatcher.map("/qwer/*/zxcv", 1)
186+
# Should not match
187+
handlers = list(
188+
self.dispatcher.handlers_for_address("/qwer/whatever/zxcvsomethingmore")
189+
)
190+
self.assertEqual(len(handlers), 0)
191+
# Should match
192+
handlers = list(self.dispatcher.handlers_for_address("/qwer/whatever/zxcv"))
193+
self.assertEqual(len(handlers), 1)
194+
184195

185196
if __name__ == "__main__":
186197
unittest.main()

0 commit comments

Comments
 (0)