RangerMauve / mqtt-regex

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

Params undefined when parameter contains a . (period) #2

Closed encojosh closed 8 years ago

encojosh commented 8 years ago

If the parameter contains a period or an underscore (and probably some more characters), the params argument is undefined. I'm not great with regular expressions, but changing the regex from ([\d\w]+/) to ([\d\w._]+/) fixes the problem for me, but I'm sure that their are other special characters that cause problems.

emitter.on("config/GET/+version", function (message, params, topic) { //params is undefined });

emitter.emit("config/GET/1.2.3", message);

RangerMauve commented 8 years ago

Thanks for filing the issue. I'll try to get to fixing it later today and add unit tests for it :D

RangerMauve commented 8 years ago

Sorry! I've been super busy and haven't had time to get to this. Ideally, it'd just be a fix where we replace ([\d\w]+/) with ([^\/#+]+). A pull request with this change would be very much appreciated. And bonus points if you add a unit test for it.

encojosh commented 8 years ago

No problem. Like I said previously, I am not very good with regex. Does this effectively mean anything except a / is captured? I knew that would be the right way to go but I didn't know how to create the regex. Additionally, would that regex need to be modified for the # wildcard?

I can create a pull request, but I may not have enough time to do proper unit testing.

RangerMauve commented 8 years ago

Yeah, basically the regex will match everything except / # and +, so basically everything that isn't special to the path. In terms of unit tests, it'd be nice to just have one that has a parameter with some sort of special character like _ or ., and then check to see that the parameter is captured properly.

RangerMauve commented 8 years ago

Sorry it took so long. Should be good now.