Skip to content

Commit e550ab1

Browse files
committed
fix: guard against empty-string crash in fieldNorm
`value.match(SPACE)` returns `null` when there are no word tokens (e.g. empty string). The old code used `!` (non-null assertion), which throws. Changed to `?.length || 1` — treats zero-token input as 1 token, producing a norm of 1.0. This can happen if a custom `getFn` returns `""` that slips past the `isBlank` guard.
1 parent be2a8dc commit e550ab1

12 files changed

Lines changed: 33 additions & 11 deletions

dist/fuse.basic.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function norm(weight = 1, mantissa = 3) {
223223
const m = Math.pow(10, mantissa);
224224
return {
225225
get(value) {
226-
const numTokens = value.match(SPACE).length;
226+
const numTokens = value.match(SPACE)?.length || 1;
227227
if (cache.has(numTokens)) {
228228
return cache.get(numTokens);
229229
}

dist/fuse.basic.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/fuse.basic.min.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/fuse.basic.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function norm(weight = 1, mantissa = 3) {
221221
const m = Math.pow(10, mantissa);
222222
return {
223223
get(value) {
224-
const numTokens = value.match(SPACE).length;
224+
const numTokens = value.match(SPACE)?.length || 1;
225225
if (cache.has(numTokens)) {
226226
return cache.get(numTokens);
227227
}

dist/fuse.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function norm(weight = 1, mantissa = 3) {
220220
const m = Math.pow(10, mantissa);
221221
return {
222222
get(value) {
223-
const numTokens = value.match(SPACE).length;
223+
const numTokens = value.match(SPACE)?.length || 1;
224224
if (cache.has(numTokens)) {
225225
return cache.get(numTokens);
226226
}

dist/fuse.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/fuse.min.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/fuse.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function norm(weight = 1, mantissa = 3) {
218218
const m = Math.pow(10, mantissa);
219219
return {
220220
get(value) {
221-
const numTokens = value.match(SPACE).length;
221+
const numTokens = value.match(SPACE)?.length || 1;
222222
if (cache.has(numTokens)) {
223223
return cache.get(numTokens);
224224
}

dist/fuse.worker.min.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/fuse.worker.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function norm(weight = 1, mantissa = 3) {
218218
const m = Math.pow(10, mantissa);
219219
return {
220220
get(value) {
221-
const numTokens = value.match(SPACE).length;
221+
const numTokens = value.match(SPACE)?.length || 1;
222222
if (cache.has(numTokens)) {
223223
return cache.get(numTokens);
224224
}

0 commit comments

Comments
 (0)