Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #747 from mcollina/escape-mongo
Browse files Browse the repository at this point in the history
escape pattern in mongo
  • Loading branch information
mcollina authored Jun 2, 2018
2 parents e61f749 + 21ad292 commit 1328828
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ db
profile-*
.__*
.idea

package-lock.json
4 changes: 3 additions & 1 deletion lib/persistence/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1328828

Please sign in to comment.