From c0d7171dbf637f70694586bcb405841378392956 Mon Sep 17 00:00:00 2001 From: Ionys <9364594+Ionys320@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:08:35 +0100 Subject: [PATCH] fix(monitors search): Make sure regex expressions are escaped. This can be reverted if the search should be regex friendly, but for the moment, it's not the case. Thanks @homelab-alpha! --- src/components/MonitorList.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/MonitorList.vue b/src/components/MonitorList.vue index 34074afab..80a47ae6e 100644 --- a/src/components/MonitorList.vue +++ b/src/components/MonitorList.vue @@ -325,7 +325,11 @@ export default { let searchTextMatch = true; if (this.searchText !== "") { try { - const regex = new RegExp(this.searchText, "i"); // "i" for case-insensitive matching + // Escape special characters for use in the regular expression + const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + + const escapedSearchText = escapeRegExp(this.searchText); + const regex = new RegExp(escapedSearchText, "i"); const safeRegexTest = (str) => str && regex.test(str);