Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def _match_topic(subscription, topic):
if sub_part == "+":
reg_ex_parts.append(r"([^\/]+)")
else:
reg_ex_parts.append(sub_part)
reg_ex_parts.append(re.escape(sub_part))

reg_ex = "^" + (r'\/'.join(reg_ex_parts)) + suffix + "$"

Expand Down
13 changes: 13 additions & 0 deletions tests/components/mqtt/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ def test_subscribe_topic_level_wildcard_and_wildcard_no_match(self):
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))

def test_subscribe_special_characters(self):
"""Test the subscription to topics with special characters."""
topic = '/test-topic/$(.)[^]{-}'
payload = 'p4y.l[]a|> ?'

mqtt.subscribe(self.hass, topic, self.record_calls)

fire_mqtt_message(self.hass, topic, payload)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual(topic, self.calls[0][0])
self.assertEqual(payload, self.calls[0][1])

def test_subscribe_binary_topic(self):
"""Test the subscription to a binary topic."""
mqtt.subscribe(self.hass, 'test-topic', self.record_calls,
Expand Down