Unverified Commit 87bb30de authored by Laila Los's avatar Laila Los
Browse files

sanitize substring in matchingTerm

parent e5197a4b
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
/**
 * 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) {