Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dist/fuse.basic.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ var BitapSearch = class {
text = isCaseSensitive ? text : text.toLowerCase();
text = ignoreDiacritics ? stripDiacritics(text) : text;
if (this.pattern === text) {
if (text.length < this.options.minMatchCharLength) return {
isMatch: false,
score: 1
};
const result = {
isMatch: true,
score: 0
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.basic.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/fuse.basic.min.mjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/fuse.basic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ var BitapSearch = class {
text = isCaseSensitive ? text : text.toLowerCase();
text = ignoreDiacritics ? stripDiacritics(text) : text;
if (this.pattern === text) {
if (text.length < this.options.minMatchCharLength) return {
isMatch: false,
score: 1
};
const result = {
isMatch: true,
score: 0
Expand Down
4 changes: 4 additions & 0 deletions dist/fuse.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ var BitapSearch = class {
text = isCaseSensitive ? text : text.toLowerCase();
text = ignoreDiacritics ? stripDiacritics(text) : text;
if (this.pattern === text) {
if (text.length < this.options.minMatchCharLength) return {
isMatch: false,
score: 1
};
const result = {
isMatch: true,
score: 0
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/fuse.min.mjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/fuse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ var BitapSearch = class {
text = isCaseSensitive ? text : text.toLowerCase();
text = ignoreDiacritics ? stripDiacritics(text) : text;
if (this.pattern === text) {
if (text.length < this.options.minMatchCharLength) return {
isMatch: false,
score: 1
};
const result = {
isMatch: true,
score: 0
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.worker.min.mjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/fuse.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ var BitapSearch = class {
text = isCaseSensitive ? text : text.toLowerCase();
text = ignoreDiacritics ? stripDiacritics(text) : text;
if (this.pattern === text) {
if (text.length < this.options.minMatchCharLength) return {
isMatch: false,
score: 1
};
const result = {
isMatch: true,
score: 0
Expand Down
7 changes: 7 additions & 0 deletions src/search/bitap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export default class BitapSearch {

// Exact match
if (this.pattern === text) {
// Respect minMatchCharLength: the whole string is the matched region, so
// its length must meet the minimum. The non-exact bitap path enforces
// this via convertMaskToIndices; the shortcut must do the same.
if (text.length < this.options.minMatchCharLength) {
return { isMatch: false, score: 1 }
}

const result: SearchResult = {
isMatch: true,
score: 0
Expand Down
22 changes: 22 additions & 0 deletions test/match.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,26 @@ describe('Fuse.match', () => {
const result = Fuse.match('apple', 'apple pie', { useTokenSearch: false })
expect(result.isMatch).toBe(true)
})

test('exact match returns isMatch: false when pattern is shorter than minMatchCharLength', () => {
// The exact-match shortcut (pattern === text) used to bypass the
// minMatchCharLength constraint, returning isMatch: true even though the
// matched region was shorter than the required minimum.
const result = Fuse.match('abc', 'abc', { minMatchCharLength: 5 })
expect(result.isMatch).toBe(false)
})

test('exact match still succeeds when pattern length meets minMatchCharLength', () => {
const result = Fuse.match('hello', 'hello', { minMatchCharLength: 5 })
expect(result.isMatch).toBe(true)
expect(result.score).toBe(0)
})

test('corpus search: exact-match item excluded when shorter than minMatchCharLength', () => {
const fuse = new Fuse(['abc', 'abcde', 'abcdefgh'], { minMatchCharLength: 5 })
const results = fuse.search('abc')
// 'abc' (3 chars) must not appear; bitap non-exact matches inside longer
// strings are correctly filtered by convertMaskToIndices already.
expect(results.map((r) => r.item)).not.toContain('abc')
})
})
Loading