Skip to content

Commit

Permalink
issue77: Fixed the invalid range error issue with the small matchee r…
Browse files Browse the repository at this point in the history
…aw topic when compared with base raw topic length (#78)

* issue77: Fixed the invalid range error issue with the small matchee raw topic when compared with base raw topic length

* Add test case for range error fix & fix typo in comments

* Fix unit test failing in wildcard case
  • Loading branch information
ashu-pietech committed Feb 10, 2024
1 parent 0f8e103 commit d034bad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/src/mqtt_subscription_topic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ class MqttSubscriptionTopic extends MqttTopic {
return false;
}
}
// If we're at the last fragment of the matchee rawTopic but there are
// more fragments in the lhs rawTopic then the matchee rawTopic
// is too specific to be a match.
if (i + 1 == matcheeTopic.topicFragments.length &&
topicFragments.length > matcheeTopic.topicFragments.length &&
lhsFragment != matcheeTopic.topicFragments[i]) {
return false;
}
// If we're at the last fragment of the lhs rawTopic but there are
// more fragments in the in the matchee then the matchee rawTopic
// more fragments in the matchee then the matchee rawTopic
// is too specific to be a match.
if (i + 1 == topicFragments.length &&
matcheeTopic.topicFragments.length > topicFragments.length) {
Expand Down
9 changes: 9 additions & 0 deletions test/mqtt_client_base_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ void main() {
expect(
subTopic.matches(MqttPublicationTopic('some/random/topic')), isFalse);
});
test('different length topics do not match and do not throw range error',
() {
const topic = 'finance/ibm/closingprice/+/topic/sub';
final subTopic = MqttSubscriptionTopic(topic);
expect(
subTopic
.matches(MqttPublicationTopic('finance/ibm/closingprice/sub')),
isFalse);
});
test(
'MultiWildcard does not match topic with difference before Wildcard level',
() {
Expand Down

0 comments on commit d034bad

Please sign in to comment.