Skip to content

Commit 52525a7

Browse files
author
attwad
committed
add test for regexp escape, escape the address passed ot the dispatcher first to not get confused if characters with special meanings were part of the osc address
1 parent 6aa6c47 commit 52525a7

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

pythonosc/dispatcher.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ def handlers_for_address(self, address_pattern):
3535
# '?' in the OSC Address Pattern matches any single character.
3636
# Let's consider numbers and _ "characters" too here, it's not said
3737
# explicitly in the specification but it sounds good.
38-
pattern = address_pattern.replace('?', '\\w?')
38+
address_pattern = re.escape(address_pattern)
39+
pattern = address_pattern.replace('\\?', '\\w?')
3940
# '*' in the OSC Address Pattern matches any sequence of zero or more
4041
# characters.
41-
pattern = pattern.replace('*', '[\\w|\\\\+]*')
42+
pattern = pattern.replace('\\*', '[\w|\+]*')
4243
# The rest of the syntax in the specification is like the re module so
4344
# we're fine.
4445
pattern = pattern + '$'

pythonosc/test/test_dispatcher.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,13 @@ def test_match_address_contains_plus_as_character(self):
8181
self.sortAndAssertSequenceEqual(
8282
[(1, [])], self.dispatcher.handlers_for_address("/foo*/bar*/*"))
8383

84-
def aatest_meh(self):
85-
ok = object()
86-
not_ok = object()
87-
self.dispatcher.map('/a+b', ok)
88-
self.dispatcher.map('/aaab', not_ok)
84+
def test_call_correct_dispatcher_on_star(self):
85+
self.dispatcher.map('/a+b', 1)
86+
self.dispatcher.map('/aaab', 2)
8987
self.sortAndAssertSequenceEqual(
90-
[(1, not_ok)], self.dispatcher.handlers_for_address('/aaab'))
91-
#self.sortAndAssertSequenceEqual(
92-
# [ok], self.dispatcher.handlers_for_address('/a+b'))
93-
94-
# in the client
95-
client.send('/a+b') # should trigger only_correct_dispatcher only!
88+
[(2, [])], self.dispatcher.handlers_for_address('/aaab'))
89+
self.sortAndAssertSequenceEqual(
90+
[(1, [])], self.dispatcher.handlers_for_address('/a+b'))
9691

9792
if __name__ == "__main__":
9893
unittest.main()

0 commit comments

Comments
 (0)