Fix pattern matching test.
This commit is contained in:
parent
d5dfd575b3
commit
f9f3fdbfe3
@ -271,31 +271,10 @@ int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *top
|
||||
tpos = 0;
|
||||
|
||||
while(spos < sublen && tpos <= topiclen){
|
||||
if(tpos == topiclen || sub[spos] == topic[tpos]){
|
||||
if(tpos == topiclen-1){
|
||||
/* Check for e.g. foo matching foo/# */
|
||||
if(spos == sublen-3
|
||||
&& sub[spos+1] == '/'
|
||||
&& sub[spos+2] == '#'){
|
||||
*result = true;
|
||||
multilevel_wildcard = true;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
}
|
||||
spos++;
|
||||
tpos++;
|
||||
if(spos == sublen && tpos == topiclen){
|
||||
*result = true;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}else if(tpos == topiclen && spos == sublen-1 && sub[spos] == '+'){
|
||||
if(spos > 0 && sub[spos-1] != '/'){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
spos++;
|
||||
*result = true;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
if(topic[tpos] == '+' || topic[tpos] == '#'){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
if(tpos == topiclen || sub[spos] != topic[tpos]){ /* Check for wildcard matches */
|
||||
if(sub[spos] == '+'){
|
||||
/* Check for bad "+foo" or "a/+foo" subscription */
|
||||
if(spos > 0 && sub[spos-1] != '/'){
|
||||
@ -343,6 +322,33 @@ int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *top
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Valid input, but no match */
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
/* sub[spos] == topic[tpos] */
|
||||
if(tpos == topiclen-1){
|
||||
/* Check for e.g. foo matching foo/# */
|
||||
if(spos == sublen-3
|
||||
&& sub[spos+1] == '/'
|
||||
&& sub[spos+2] == '#'){
|
||||
*result = true;
|
||||
multilevel_wildcard = true;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
}
|
||||
spos++;
|
||||
tpos++;
|
||||
if(spos == sublen && tpos == topiclen){
|
||||
*result = true;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}else if(tpos == topiclen && spos == sublen-1 && sub[spos] == '+'){
|
||||
if(spos > 0 && sub[spos-1] != '/'){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
spos++;
|
||||
*result = true;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ pattern_test("foo/+/baz/#", "foo/bar/baz")
|
||||
pattern_test("foo/+/baz/#", "foo/bar/baz/bar")
|
||||
pattern_test("foo/foo/baz/#", "foo/foo/baz/bar")
|
||||
pattern_test("foo/#", "foo")
|
||||
pattern_test("foo/#", "foo/")
|
||||
pattern_test("/#", "/foo")
|
||||
pattern_test("test/topic/", "test/topic/")
|
||||
pattern_test("test/topic/+", "test/topic/")
|
||||
|
Loading…
Reference in New Issue
Block a user