mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 13:37:34 +08:00
Fix # matching logic
E.g. given the expression `foo/#`: - `foo/bar` matches - `foo/` should not match - `foo` should not match PUBLISHED_FROM=40f3290cb9a478b22d9f1ab6382884b5de70e266
This commit is contained in:
parent
3942914945
commit
349d25dccf
17
mongoose.c
17
mongoose.c
@ -9706,10 +9706,21 @@ static void mg_mqtt_proto_data_destructor(void *proto_data) {
|
|||||||
int mg_mqtt_match_topic_expression(struct mg_str exp, struct mg_str topic) {
|
int mg_mqtt_match_topic_expression(struct mg_str exp, struct mg_str topic) {
|
||||||
/* TODO(mkm): implement real matching */
|
/* TODO(mkm): implement real matching */
|
||||||
if (memchr(exp.p, '#', exp.len)) {
|
if (memchr(exp.p, '#', exp.len)) {
|
||||||
exp.len -= 2;
|
/* exp `foo/#` will become `foo/` */
|
||||||
if (topic.len < exp.len) {
|
exp.len -= 1;
|
||||||
exp.len = topic.len;
|
/*
|
||||||
|
* topic should be longer than the expression: e.g. topic `foo/bar` does
|
||||||
|
* match `foo/#`, but neither `foo` nor `foo/` do.
|
||||||
|
*/
|
||||||
|
if (topic.len <= exp.len) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Truncate topic so that it'll pass the next length check */
|
||||||
|
topic.len = exp.len;
|
||||||
|
}
|
||||||
|
if (topic.len != exp.len) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return strncmp(topic.p, exp.p, exp.len) == 0;
|
return strncmp(topic.p, exp.p, exp.len) == 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user