Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Feb 10, 2024
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
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
Loading