recent_topics: Avoid regexps in topic_in_search_results.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-07-29 13:22:29 -07:00
committed by Tim Abbott
parent 4a26bde4bd
commit 1be2cf6d8a

View File

@@ -227,17 +227,9 @@ exports.topic_in_search_results = function (keyword, stream, topic) {
if (keyword === "") {
return true;
}
// Escape speacial characters from input.
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
keyword = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const text = (stream + " " + topic).toLowerCase().replace(/\s+/g, " ");
const search_words = keyword.toLowerCase().replace(/\s+/g, " ").split(" ");
return search_words.every((word) => {
if (text.search(word) !== -1) {
return true;
}
return false;
});
const text = (stream + " " + topic).toLowerCase();
const search_words = keyword.toLowerCase().split(/\s+/);
return search_words.every((word) => text.includes(word));
};
exports.update_topics_of_message_ids = function (message_ids) {