mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
recent_topics: Avoid regexps in topic_in_search_results.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
4a26bde4bd
commit
1be2cf6d8a
@@ -227,17 +227,9 @@ exports.topic_in_search_results = function (keyword, stream, topic) {
|
|||||||
if (keyword === "") {
|
if (keyword === "") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Escape speacial characters from input.
|
const text = (stream + " " + topic).toLowerCase();
|
||||||
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
const search_words = keyword.toLowerCase().split(/\s+/);
|
||||||
keyword = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
return search_words.every((word) => text.includes(word));
|
||||||
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;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update_topics_of_message_ids = function (message_ids) {
|
exports.update_topics_of_message_ids = function (message_ids) {
|
||||||
|
|||||||
Reference in New Issue
Block a user