Fix @all spam warning when typing @all in backticks.

When user'd like to send a message with @all in backticks
they see spam warning in spite of the fact that nobody
would be alerted.

Fixes: #1505.
This commit is contained in:
Tomasz Kolek 2016-08-15 22:24:40 +02:00 committed by Tim Abbott
parent 5c82e53b9a
commit b1b864341c
2 changed files with 55 additions and 1 deletions

View File

@ -140,3 +140,57 @@ var _ = global._;
assert.throws(function () { eaf3('foo'); }, /called with \d+ arguments/);
assert.throws(function () { eaf3('foo','bar', 'baz'); }, /called with \d+ arguments/);
}());
(function test_all_and_everyone_mentions_regexp() {
var messages_with_all_mentions = [
'@all',
'some text before @all some text after',
'@all some text after only',
'some text before only @all',
'@**all**',
'some text before @**all** some text after',
'@**all** some text after only',
'some text before only @**all**'
];
var messages_with_everyone_mentions = [
'@everyone',
'some text before @everyone some text after',
'@everyone some text after only',
'some text before only @everyone',
'@**everyone**',
'some text before @**everyone** some text after',
'@**everyone** some text after only',
'some text before only @**everyone**'
];
var messages_without_all_mentions = [
'`@everyone`',
'some_email@everyone.com',
'`@**everyone**`',
'some_email@**everyone**.com'
];
var messages_without_everyone_mentions = [
'`@everyone`',
'some_email@everyone.com',
'`@**everyone**`',
'some_email@**everyone**.com'
];
var i;
for(i=0; i<messages_with_all_mentions.length; i++) {
assert(util.is_all_or_everyone_mentioned(messages_with_all_mentions[i]));
}
for(i=0; i<messages_with_everyone_mentions.length; i++) {
assert(util.is_all_or_everyone_mentioned(messages_with_everyone_mentions[i]));
}
for(i=0; i<messages_without_all_mentions.length; i++) {
assert(!util.is_all_or_everyone_mentioned(messages_without_everyone_mentions[i]));
}
for(i=0; i<messages_without_everyone_mentions.length; i++) {
assert(!util.is_all_or_everyone_mentioned(messages_without_everyone_mentions[i]));
}
}());

View File

@ -233,7 +233,7 @@ exports.execute_early = function (func) {
};
exports.is_all_or_everyone_mentioned = function (message_content) {
var all_everyone_re = /(@\*{2}(all|everyone)\*{2})|(@(all|everyone))/;
var all_everyone_re = /(^|\s)(@\*{2}(all|everyone)\*{2})|(@(all|everyone))($|\s)/;
return all_everyone_re.test(message_content);
};