From 87bb30de52c2fdb1afa4ac1aacba0deb3a4307e0 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Fri, 30 Jun 2023 14:34:28 +0200 Subject: [PATCH] sanitize substring in matchingTerm --- client/src/components/Panels/utilities.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/components/Panels/utilities.js b/client/src/components/Panels/utilities.js index 2ce7843f3281..8bbc5385f68d 100644 --- a/client/src/components/Panels/utilities.js +++ b/client/src/components/Panels/utilities.js @@ -1,7 +1,7 @@ /** * Utilities file for Panel Searches (panel/client search + advanced/backend search) */ -import { orderBy, escapeRegExp } from "lodash"; +import { orderBy } from "lodash"; import levenshteinDistance from "utils/levenshtein"; const TOOLS_RESULTS_SORT_LABEL = "apiSort"; @@ -252,9 +252,11 @@ function isToolObject(tool) { // given array and a substring, get the closest matching term for substring function matchingTerm(termArray, substring) { + const sanitized = sanitizeString(substring); + for (const i in termArray) { const term = termArray[i]; - if (term.match(substring)) { + if (term.match(sanitized)) { return term; } } @@ -273,8 +275,8 @@ function sanitizeString(value, targets = [], substitute = "") { targets.forEach((rep) => { sanitized = sanitized.replaceAll(rep, substitute); }); - sanitized = escapeRegExp(sanitized); - return sanitized; + + return sanitized.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } function flattenToolsSection(section) {