Skip to content

Commit

Permalink
Merge pull request #16351 from ElectronicBlueberry/toolbox-regex
Browse files Browse the repository at this point in the history
[23.1] Sanitize substring in matchingTerm
  • Loading branch information
mvdbeek committed Jun 30, 2023
2 parents e5197a4 + 87bb30d commit a37eec2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions 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";
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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) {
Expand Down

0 comments on commit a37eec2

Please sign in to comment.