RangerMauve / mqtt-regex

Converts an MQTT topic with parameters into a regular expression.
MIT License
20 stars 1 forks source link

Topics with trailing hashes matched incorrectly #4

Open ajlennon opened 5 years ago

ajlennon commented 5 years ago

Hi, nice work thanks.

I've been doing some testing and the regexp generated seems to match topics with trailing slashes incorrectly e.g. changing the test case to:

var tests = {
        basic: {
                pattern: "foo/bar/baz",
                tests: ["foo/bar/baz", "foo/bar/baz/"]
        },
}

The result is that both foo/bar/baz and foo/bar/baz/ match against the pattern, but the second should not match (imho). I've tested this with MQtt.fx and Mosquitto and they are different subscriptions

RangerMauve commented 5 years ago

Hi, thanks for the bug report! This library has been superseded by mqtt-pattern, so I don't think it's worth it to add bug fixes for now.. Could you try that out and see if it works correctly? The performance is a lot better since it doesn't use regex.

ajlennon commented 5 years ago

Hi! No worries

I need to use RegEx unfortunately for various reasons (querying a legacy SQLITE database)

I've had some tweet conversations with the guy behind MQtt fwiw and I think I have it clarified!

I think I have some workarounds...

For ref: https://twitter.com/embedded_iot/status/1065205033824862208

Cheers!

RangerMauve commented 5 years ago

If you're planning on making a port anyways, you can ignore this line of code where I explicitly ignore the trailing slash. 😀