Fix `mosquitto_topic_matches_sub()` behaviour with wildcards in topic.

It was not returning MOSQ_ERR_INVAL if the topic contains a wildcard.

Closes #1589. Thanks to mdelete.
pull/1588/head
Roger A. Light 6 years ago
parent f16d9e2bcf
commit 8d5fd7d1e2

@ -17,6 +17,8 @@ Broker:
Client library:
- Set minimum keepalive argument to `mosquitto_connect*()` to be 5 seconds.
Closes #1550.
- Fix `mosquitto_topic_matches_sub()` not returning MOSQ_ERR_INVAL if the
topic contains a wildcard. Closes #1589.
Clients:
- Fix `--remove-retained` not obeying the `-T` option for filtering out

@ -219,6 +219,9 @@ int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *top
spos++;
sub++;
while(topic[0] != 0 && topic[0] != '/'){
if(topic[0] == '+' || topic[0] == '#'){
return MOSQ_ERR_INVAL;
}
topic++;
}
if(topic[0] == 0 && sub[0] == 0){
@ -234,6 +237,12 @@ int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *top
if(sub[1] != 0){
return MOSQ_ERR_INVAL;
}else{
while(topic[0] != 0){
if(topic[0] == '+' || topic[0] == '#'){
return MOSQ_ERR_INVAL;
}
topic++;
}
*result = true;
return MOSQ_ERR_SUCCESS;
}
@ -292,6 +301,12 @@ int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *top
if((topic[0] != 0 || sub[0] != 0)){
*result = false;
}
while(topic[0] != 0){
if(topic[0] == '+' || topic[0] == '#'){
return MOSQ_ERR_INVAL;
}
topic++;
}
return MOSQ_ERR_SUCCESS;
}

@ -20,6 +20,9 @@ static void no_match_helper(int rc_expected, const char *sub, const char *topic)
rc = mosquitto_topic_matches_sub(sub, topic, &match);
CU_ASSERT_EQUAL(rc, rc_expected);
if(rc != rc_expected){
printf("%d:%d %s:%s\n", rc, rc_expected, sub, topic);
}
CU_ASSERT_EQUAL(match, false);
}
@ -135,6 +138,16 @@ static void TEST_invalid_but_matching(void)
no_match_helper(MOSQ_ERR_INVAL, "foo/bar#", "foo/bar#");
no_match_helper(MOSQ_ERR_INVAL, "foo+", "fooa");
no_match_helper(MOSQ_ERR_INVAL, "foo/+", "foo/+");
no_match_helper(MOSQ_ERR_INVAL, "foo/#", "foo/+");
no_match_helper(MOSQ_ERR_INVAL, "foo/+", "foo/bar/+");
no_match_helper(MOSQ_ERR_INVAL, "foo/#", "foo/bar/+");
no_match_helper(MOSQ_ERR_INVAL, "foo/+", "foo/#");
no_match_helper(MOSQ_ERR_INVAL, "foo/#", "foo/#");
no_match_helper(MOSQ_ERR_INVAL, "foo/+", "foo/bar/#");
no_match_helper(MOSQ_ERR_INVAL, "foo/#", "foo/bar/#");
}

Loading…
Cancel
Save