correct MQTT subscription filter#7269
Merged
Merged
Conversation
|
@amigian74, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @pvizeli and @fabaff to be potential reviewers. |
Contributor
|
Hi @amigian74, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
Member
|
Please add tests to show that this is working. |
houndci-bot
reviewed
May 2, 2017
| """Test the subscription of wildcard topics.""" | ||
| mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls) | ||
|
|
||
| fire_mqtt_message(self.hass, 'hello/another-test-topic', 'test-payload') |
| """Test the subscription of wildcard topics.""" | ||
| mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls) | ||
|
|
||
| fire_mqtt_message(self.hass, 'hello/here-iam/test-topic', 'test-payload') |
| self.assertEqual('hello/test-topic/here-iam', self.calls[0][0]) | ||
| self.assertEqual('test-payload', self.calls[0][1]) | ||
|
|
||
| def test_subscribe_topic_level_wildcard_and_wildcard_level_wildcard_no_match(self): |
| """Test the subscription of wildcard topics.""" | ||
| mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls) | ||
|
|
||
| fire_mqtt_message(self.hass, 'hello/test-topic/here-iam', 'test-payload') |
houndci-bot
reviewed
May 2, 2017
| """Test the subscription of wildcard topics.""" | ||
| mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls) | ||
|
|
||
| fire_mqtt_message(self.hass, 'hello/another-test-topic', 'test-payload') |
| """Test the subscription of wildcard topics.""" | ||
| mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls) | ||
|
|
||
| fire_mqtt_message(self.hass, 'hello/here-iam/test-topic', 'test-payload') |
| self.assertEqual('hello/test-topic/here-iam', self.calls[0][0]) | ||
| self.assertEqual('test-payload', self.calls[0][1]) | ||
|
|
||
| def test_subscribe_topic_level_wildcard_and_wildcard_level_wildcard_no_match(self): |
| """Test the subscription of wildcard topics.""" | ||
| mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls) | ||
|
|
||
| fire_mqtt_message(self.hass, 'hello/test-topic/here-iam', 'test-payload') |
import order changed
Member
|
Perfect, thanks! 🐬 |
Merged
pezinek
reviewed
Jun 15, 2017
| if sub_part == "+": | ||
| reg_ex_parts.append(r"([^\/]+)") | ||
| else: | ||
| reg_ex_parts.append(sub_part) |
Contributor
There was a problem hiding this comment.
This is not escaping the characters that do have special meaning in regular expressions, and in fact causes issue #7478. Using regular expressions in case where both subscription and topic are variables is only asking for troubles and this fix should be reverted IMO.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current topic filter within the mqtt component won't match something like "+/something/#". This change should work for all subscriptions
Issue: #6449