提交 73d7b085 编写于 作者: J Johannes Rieken

don't search for nothing, fixes #26423

上级 6e3427b1
......@@ -478,6 +478,9 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
return undefined;
}
// keep track of the maximum score
let maxScore = -1;
for (i = 1; i <= patternLen; i++) {
let lastLowWordChar = '';
......@@ -509,6 +512,9 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
}
_scores[i][j] = score;
if (score > maxScore) {
maxScore = score;
}
let diag = _table[i - 1][j - 1] + (score > 1 ? 1 : score);
let top = _table[i - 1][j] + -1;
......@@ -544,6 +550,10 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
}
}
if (maxScore <= 1) {
return undefined;
}
if (_debug) {
console.log(printTable(_table, pattern, patternLen, word, wordLen));
console.log(printTable(_arrows, pattern, patternLen, word, wordLen));
......
......@@ -305,6 +305,21 @@ suite('Filters', () => {
);
});
test('fuzzyScore, issue #26423', function () {
assertMatches(
'fsfsfs',
'dsafdsafdsafdsafdsafdsafdsafasdfdsa',
undefined,
fuzzyScore
);
assertMatches(
'fsfsfsfsfsfsfsf',
'dsafdsafdsafdsafdsafdsafdsafasdfdsafdsafdsafdsafdsfdsafdsfdfdfasdnfdsajfndsjnafjndsajlknfdsa',
undefined,
fuzzyScore
);
});
function assertTopScore(filter: typeof fuzzyScore, pattern: string, expected: number, ...words: string[]) {
let topScore = -(100 * 10);
let topIdx = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册