mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 05:26:15 +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) {
|
||||
/* TODO(mkm): implement real matching */
|
||||
if (memchr(exp.p, '#', exp.len)) {
|
||||
exp.len -= 2;
|
||||
if (topic.len < exp.len) {
|
||||
exp.len = topic.len;
|
||||
/* exp `foo/#` will become `foo/` */
|
||||
exp.len -= 1;
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user