diff --git a/.gitignore b/.gitignore index ad95556..836bd64 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ db profile-* .__* .idea + +package-lock.json diff --git a/lib/persistence/mongo.js b/lib/persistence/mongo.js index 4681a9b..1bbc0c2 100644 --- a/lib/persistence/mongo.js +++ b/lib/persistence/mongo.js @@ -25,6 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. "use strict"; var AbstractPersistence = require("./abstract"); +var escape = require('escape-string-regexp'); var mongo = require('mongodb'); var MongoClient = mongo.MongoClient; var util = require("util"); @@ -267,7 +268,8 @@ MongoPersistence.prototype.storeRetained = function(packet, cb) { }; MongoPersistence.prototype.lookupRetained = function(pattern, cb) { - var regexp = new RegExp(pattern.replace(/(#|\+)/, ".+").replace('\\', '\\\\')); + var actual = escape(pattern).replace(/(#|\\\+).*$/, ''); + var regexp = new RegExp(actual); var stream = this._retained.find({ topic: { $regex: regexp } }).stream(); var matched = []; var matcher = new Matcher(); diff --git a/package.json b/package.json index 93b9401..6b646dd 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "clone": "^1.0.2", "commander": "~2.9.0", "deepcopy": "^0.6.1", + "escape-string-regexp": "^1.0.5", "extend": "^3.0.0", "json-buffer": "~2.0.11", "jsonschema": "^1.0.3",