@@ -275,11 +275,16 @@ public static boolean isMatched(String topicFilter, String topicName) throws Ill
275
275
}
276
276
277
277
while (filterPos < filterLen && topicPos < topicLen ) {
278
- if (topicFilter .charAt (filterPos ) == '#' )
279
- topicPos = topicLen - 1 ; // skip until end of string
280
-
278
+ if (topicFilter .charAt (filterPos ) == '#' ) {
279
+ /*
280
+ * next 'if' will break when topicFilter = topic/# and topicName topic/A/,
281
+ * but they are matched
282
+ */
283
+ topicPos = topicLen ;
284
+ filterPos = filterLen ;
285
+ break ;
286
+ }
281
287
if (topicName .charAt (topicPos ) == '/' && topicFilter .charAt (filterPos ) != '/' )
282
-
283
288
break ;
284
289
if (topicFilter .charAt (filterPos ) != '+' && topicFilter .charAt (filterPos ) != '#'
285
290
&& topicFilter .charAt (filterPos ) != topicName .charAt (topicPos ))
@@ -301,11 +306,11 @@ public static boolean isMatched(String topicFilter, String topicName) throws Ill
301
306
* https://github.com/eclipse/paho.mqtt.java/issues/418
302
307
* Covers edge case to match sport/# to sport
303
308
*/
304
- if ((topicFilter .length () - topicName . length ()) == 2 &&
305
- topicFilter . substring ( topicFilter . length () - 2 , topicFilter .length ()). equals ( "/#" )) {
306
- String filterSub = topicFilter . substring ( 0 , topicFilter . length () - 2 ) ;
307
- if (filterSub . equals ( topicName )) {
308
- System . err . println ( "filterSub equals topicName: " + filterSub + " == " + topicName );
309
+ if ((topicFilter .length () - filterPos > 0 ) && ( topicPos == topicLen )) {
310
+ if ( topicName . charAt ( topicPos - 1 ) == '/' && topicFilter .charAt ( filterPos ) == '#' )
311
+ return true ;
312
+ if (topicFilter . length () - filterPos > 1
313
+ && topicFilter . substring ( filterPos , filterPos + 2 ). equals ( "/#" )) {
309
314
return true ;
310
315
}
311
316
}
0 commit comments