Skip to content

Commit

Permalink
fix: strictly check for null in abstract cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Oct 21, 2022
1 parent ec9c6fb commit 8ef1fe6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cursor/abstract_cursor.ts
Expand Up @@ -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.';
Expand Down Expand Up @@ -774,7 +777,10 @@ export function next<T>(
// 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);
Expand Down

0 comments on commit 8ef1fe6

Please sign in to comment.