mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Previously, we were checking if a particular user was the current user in dozens of places in the codebase, and correct case-insensitive checks were not used consistently, leading to bugs like #502.
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
var alert_words = (function () {
 | 
						|
 | 
						|
var exports = {};
 | 
						|
 | 
						|
exports.words = page_params.alert_words;
 | 
						|
 | 
						|
// escape_user_regex taken from jquery-ui/autocomplete.js,
 | 
						|
// licensed under MIT license.
 | 
						|
function escape_user_regex(value) {
 | 
						|
    return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
 | 
						|
}
 | 
						|
 | 
						|
var find_href_backwards = /href=['"][\w:\/\.]+$/;
 | 
						|
var find_title_backwards = /title=['"][\w:\/\.]+$/;
 | 
						|
 | 
						|
exports.process_message = function (message) {
 | 
						|
    if (!exports.notifies(message)) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    _.each(exports.words, function (word) {
 | 
						|
        var clean = escape_user_regex(word);
 | 
						|
        var before_punctuation = '\\s|^|>|[\\(\\".,\';\\[]';
 | 
						|
        var after_punctuation = '\\s|$|<|[\\)\\"\\?!:.,\';\\]!]';
 | 
						|
 | 
						|
 | 
						|
        var word_in_href = new RegExp(find_href_backwards + word, 'i');
 | 
						|
 | 
						|
        var regex = new RegExp('(' + before_punctuation + ')' +
 | 
						|
                               '(' + clean + ')' +
 | 
						|
                               '(' + after_punctuation + ')' , 'ig');
 | 
						|
        message.content = message.content.replace(regex, function (match, before, word, after, offset, content) {
 | 
						|
            // Don't munge URL hrefs
 | 
						|
            var pre_match = content.substring(0, offset);
 | 
						|
            if (find_href_backwards.exec(pre_match) || find_title_backwards.exec(pre_match)) {
 | 
						|
                return before + word + after;
 | 
						|
            } else {
 | 
						|
                return before + "<span class='alert-word'>" + word + "</span>" + after;
 | 
						|
            }
 | 
						|
        });
 | 
						|
    });
 | 
						|
};
 | 
						|
 | 
						|
exports.notifies = function (message) {
 | 
						|
    return !util.is_current_user(message.sender_email) && message.alerted;
 | 
						|
};
 | 
						|
 | 
						|
return exports;
 | 
						|
 | 
						|
}());
 | 
						|
if (typeof module !== 'undefined') {
 | 
						|
    module.exports = alert_words;
 | 
						|
}
 |