Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: chowen <chowen.dev@gmail.com>
ChowenPan committed Jun 22, 2020
1 parent d11139f commit cb96037
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -275,11 +275,16 @@ public static boolean isMatched(String topicFilter, String topicName) throws Ill
}

while (filterPos < filterLen && topicPos < topicLen) {
if (topicFilter.charAt(filterPos) == '#')
topicPos = topicLen - 1; // skip until end of string

if (topicFilter.charAt(filterPos) == '#') {
/*
* next 'if' will break when topicFilter = topic/# and topicName topic/A/,
* but they are matched
*/
topicPos = topicLen;
filterPos = filterLen;
break;
}
if (topicName.charAt(topicPos) == '/' && topicFilter.charAt(filterPos) != '/')

break;
if (topicFilter.charAt(filterPos) != '+' && topicFilter.charAt(filterPos) != '#'
&& topicFilter.charAt(filterPos) != topicName.charAt(topicPos))
@@ -301,11 +306,11 @@ public static boolean isMatched(String topicFilter, String topicName) throws Ill
* https://github.com/eclipse/paho.mqtt.java/issues/418
* Covers edge case to match sport/# to sport
*/
if ((topicFilter.length() - topicName.length()) == 2 &&
topicFilter.substring(topicFilter.length() -2, topicFilter.length()).equals("/#")) {
String filterSub = topicFilter.substring(0, topicFilter.length() - 2);
if (filterSub.equals(topicName)) {
System.err.println("filterSub equals topicName: " + filterSub + " == " + topicName);
if ((topicFilter.length() - filterPos > 0) && (topicPos == topicLen)) {
if (topicName.charAt(topicPos - 1) == '/' && topicFilter.charAt(filterPos) == '#')
return true;
if (topicFilter.length() - filterPos > 1
&& topicFilter.substring(filterPos, filterPos + 2).equals("/#")) {
return true;
}
}

0 comments on commit cb96037

Please sign in to comment.