Commit 349d25dc authored by Dmitry Frank's avatar Dmitry Frank Committed by Cesanta Bot

Fix # matching logic

E.g. given the expression `foo/#`:

- `foo/bar` matches
- `foo/` should not match
- `foo` should not match

PUBLISHED_FROM=40f3290cb9a478b22d9f1ab6382884b5de70e266
parent 39429149
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment