mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Fixed recursive matching arguments
This commit is contained in:
parent
47bbefd81f
commit
ba66fd6546
2 changed files with 12 additions and 12 deletions
|
@ -71,12 +71,12 @@ function fuzzyMatchRecursive(
|
||||||
|
|
||||||
// Return if recursion limit is reached.
|
// Return if recursion limit is reached.
|
||||||
if (++recursionCount >= recursionLimit) {
|
if (++recursionCount >= recursionLimit) {
|
||||||
return [false, outScore];
|
return [false, outScore, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return if we reached ends of strings.
|
// Return if we reached ends of strings.
|
||||||
if (patternCurIndex === pattern.length || strCurrIndex === str.length) {
|
if (patternCurIndex === pattern.length || strCurrIndex === str.length) {
|
||||||
return [false, outScore];
|
return [false, outScore, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursion params
|
// Recursion params
|
||||||
|
@ -92,7 +92,7 @@ function fuzzyMatchRecursive(
|
||||||
pattern[patternCurIndex].toLowerCase() === str[strCurrIndex].toLowerCase()
|
pattern[patternCurIndex].toLowerCase() === str[strCurrIndex].toLowerCase()
|
||||||
) {
|
) {
|
||||||
if (nextMatch >= maxMatches) {
|
if (nextMatch >= maxMatches) {
|
||||||
return [false, outScore];
|
return [false, outScore, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstMatch && srcMatches) {
|
if (firstMatch && srcMatches) {
|
||||||
|
@ -100,8 +100,7 @@ function fuzzyMatchRecursive(
|
||||||
firstMatch = false;
|
firstMatch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const recursiveMatches = [];
|
const [matched, recursiveScore, recursiveMatches] = fuzzyMatchRecursive(
|
||||||
const [matched, recursiveScore] = fuzzyMatchRecursive(
|
|
||||||
pattern,
|
pattern,
|
||||||
str,
|
str,
|
||||||
patternCurIndex,
|
patternCurIndex,
|
||||||
|
@ -181,16 +180,17 @@ function fuzzyMatchRecursive(
|
||||||
// Return best result
|
// Return best result
|
||||||
if (recursiveMatch && (!matched || bestRecursiveScore > outScore)) {
|
if (recursiveMatch && (!matched || bestRecursiveScore > outScore)) {
|
||||||
// Recursive score is better than "this"
|
// Recursive score is better than "this"
|
||||||
|
matches = bestRecursiveMatches;
|
||||||
outScore = bestRecursiveScore;
|
outScore = bestRecursiveScore;
|
||||||
return [true, outScore, calcMatchRanges(matches)];
|
return [true, outScore, matches];
|
||||||
} else if (matched) {
|
} else if (matched) {
|
||||||
// "this" score is better than recursive
|
// "this" score is better than recursive
|
||||||
return [true, outScore, calcMatchRanges(matches)];
|
return [true, outScore, matches];
|
||||||
} else {
|
} else {
|
||||||
return [false, outScore];
|
return [false, outScore, matches];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [false, outScore];
|
return [false, outScore, matches];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,7 +200,7 @@ function fuzzyMatchRecursive(
|
||||||
* @param [number] matches
|
* @param [number] matches
|
||||||
* @returns [[number]]
|
* @returns [[number]]
|
||||||
*/
|
*/
|
||||||
function calcMatchRanges(matches) {
|
export function calcMatchRanges(matches) {
|
||||||
const ranges = [];
|
const ranges = [];
|
||||||
let start = matches[0],
|
let start = matches[0],
|
||||||
curr = start;
|
curr = start;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import HTMLOperation from "../HTMLOperation.mjs";
|
import HTMLOperation from "../HTMLOperation.mjs";
|
||||||
import Sortable from "sortablejs";
|
import Sortable from "sortablejs";
|
||||||
import {fuzzyMatch} from "../../core/lib/FuzzySearch.mjs";
|
import {fuzzyMatch, calcMatchRanges} from "../../core/lib/FuzzySearch.mjs";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,7 +123,7 @@ class OperationsWaiter {
|
||||||
if (nameMatch || descPos >= 0) {
|
if (nameMatch || descPos >= 0) {
|
||||||
const operation = new HTMLOperation(opName, this.app.operations[opName], this.app, this.manager);
|
const operation = new HTMLOperation(opName, this.app.operations[opName], this.app, this.manager);
|
||||||
if (highlight) {
|
if (highlight) {
|
||||||
operation.highlightSearchStrings(idxs || [], [[descPos, searchStr.length]]);
|
operation.highlightSearchStrings(calcMatchRanges(idxs) || [], [[descPos, searchStr.length]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nameMatch) {
|
if (nameMatch) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue