Skip to content

Commit

Permalink
fix(monitors search): Correctly handle null/undefined/empty values. A…
Browse files Browse the repository at this point in the history
…lso optimize a bit search tags by replacing `.find` with `.some`.

Thanks @homelab-alpha
  • Loading branch information
Ionys320 committed Dec 22, 2024
1 parent 1e03429 commit d0d03c0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/MonitorList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,21 @@ export default {
// finds monitor name, tag name or tag value
let searchTextMatch = true;
if (this.searchText !== "") {
const regex = new RegExp(this.searchText, "i");
searchTextMatch =
regex.test(monitor.name) ||
regex.test(monitor.url) ||
regex.test(monitor.hostname) ||
regex.test(monitor.dns_resolve_server) ||
monitor.tags.find((tag) => regex.test(tag.name) || regex.test(tag.value));
try {
const regex = new RegExp(this.searchText, "i"); // "i" for case-insensitive matching
const safeRegexTest = (str) => str && regex.test(str);
searchTextMatch =
regex.test(monitor.name) ||
safeRegexTest(monitor.url) ||
safeRegexTest(monitor.hostname) ||
safeRegexTest(monitor.dns_resolve_server) ||
monitor.tags.some(tag => regex.test(tag.name) || safeRegexTest(tag.value));
} catch (e) {
console.error("Invalid regex pattern:", e);
searchTextMatch = false;
}
}
// filter by status
Expand Down

0 comments on commit d0d03c0

Please sign in to comment.