From 8ef1fe6287ab6239c1a1b45a66cb482e90e15d61 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Fri, 21 Oct 2022 13:46:52 -0400 Subject: [PATCH] fix: strictly check for null in abstract cursor --- src/cursor/abstract_cursor.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cursor/abstract_cursor.ts b/src/cursor/abstract_cursor.ts index 63368a9e39..5d41ed523a 100644 --- a/src/cursor/abstract_cursor.ts +++ b/src/cursor/abstract_cursor.ts @@ -295,7 +295,10 @@ export abstract class AbstractCursor< while (true) { const document = await this.next(); - if (document == null) { + // Intentional strict null check, because users can map cursors to falsey values. + // We allow mapping to all values except for null. + // eslint-disable-next-line no-restricted-syntax + if (document === null) { if (!this.closed) { const message = 'Cursor returned a `null` document, but the cursor is not exhausted. Mapping documents to `null` is not supported in the cursor transform.'; @@ -774,7 +777,10 @@ export function next( // All cursors must operate within a session, one must be made implicitly if not explicitly provided cursor[kInit]((err, value) => { if (err) return callback(err); - if (value != null) { + // Intentional strict null check, because users can map cursors to falsey values. + // We allow mapping to all values except for null. + // eslint-disable-next-line no-restricted-syntax + if (value !== null) { return callback(undefined, value); } return next(cursor, blocking, callback);