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;
|
tpos = 0;
|
||||||
|
|
||||||
while(spos < sublen && tpos <= topiclen){
|
while(spos < sublen && tpos <= topiclen){
|
||||||
if(tpos == topiclen || sub[spos] == topic[tpos]){
|
if(topic[tpos] == '+' || 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;
|
return MOSQ_ERR_INVAL;
|
||||||
}
|
}
|
||||||
spos++;
|
if(tpos == topiclen || sub[spos] != topic[tpos]){ /* Check for wildcard matches */
|
||||||
*result = true;
|
|
||||||
return MOSQ_ERR_SUCCESS;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(sub[spos] == '+'){
|
if(sub[spos] == '+'){
|
||||||
/* Check for bad "+foo" or "a/+foo" subscription */
|
/* Check for bad "+foo" or "a/+foo" subscription */
|
||||||
if(spos > 0 && sub[spos-1] != '/'){
|
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;
|
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;
|
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/+/baz/#", "foo/bar/baz/bar")
|
||||||
pattern_test("foo/foo/baz/#", "foo/foo/baz/bar")
|
pattern_test("foo/foo/baz/#", "foo/foo/baz/bar")
|
||||||
pattern_test("foo/#", "foo")
|
pattern_test("foo/#", "foo")
|
||||||
|
pattern_test("foo/#", "foo/")
|
||||||
pattern_test("/#", "/foo")
|
pattern_test("/#", "/foo")
|
||||||
pattern_test("test/topic/", "test/topic/")
|
pattern_test("test/topic/", "test/topic/")
|
||||||
pattern_test("test/topic/+", "test/topic/")
|
pattern_test("test/topic/+", "test/topic/")
|
||||||
|
Loading…
Reference in New Issue
Block a user