Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

recent_topics: Avoid regexps in topic_in_search_results.

Anders Kaseorg1be2cf6d8adf
diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js
index 992810ea559..d160ae08ef4 100644
--- a/static/js/recent_topics.js
+++ b/static/js/recent_topics.js
@@ -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) {