1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-19 16:42:09 +03:00

Fix linting & c+p errors

This commit is contained in:
David Baker
2015-06-29 18:20:36 +01:00
parent 22f08e4e5b
commit 9416a9a8a3

View File

@@ -150,27 +150,28 @@ module.exports = function(client) {
var val = valueForDottedKey(cond.key, ev);
if (!val || typeof val != 'string') { return false; }
var pat;
if (cond.key == 'content.body') {
pat = '\\b'+globToRegexp(cond.pattern)+'\\b';
pat = '\\b' + globToRegexp(cond.pattern) + '\\b';
} else {
pat = '^'+globToRegexp(cond.pattern)+'$';
pat = '^' + globToRegexp(cond.pattern) + '$';
}
var val = valueForDottedKey(cond['key'], ev);
if (!val || typeof val != 'string') return false;
var regex = new RegExp(pat, 'i');
return !!val.match(regex);
};
var globToRegexp = function(glob) {
// From https://github.com/matrix-org/synapse/blob/abbee6b29be80a77e05730707602f3bbfc3f38cb/synapse/push/__init__.py#L132
// Because micromatch is about 130KB with dependencies, and minimatch is not much better.
// From
// https://github.com/matrix-org/synapse/blob/abbee6b29be80a77e05730707602f3bbfc3f38cb/synapse/push/__init__.py#L132
// Because micromatch is about 130KB with dependencies,
// and minimatch is not much better.
var pat = escapeRegExp(glob);
pat = pat.replace(/\\\*/, '.*');
pat = pat.replace(/\?/, '.');
pat = pat.replace(/\\\[(!|)(.*)\\]/, function(match, p1, p2, offset, string) {
var first = p1 && '^' || '';
var second = p2.replace(/\\\-/, '-');
return '['+first+second+']';
return '[' + first + second + ']';
});
return pat;
};