Skip to content

Commit

Permalink
fix(src): protect against bad key-exclusion issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed Aug 26, 2021
1 parent 4244ed3 commit a81a5f5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/backend/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ export async function itemExists<T>(
}
}

if (key == '_id' && options?.exclude_id) {
throw new GuruMeditationError(
'assert failed: cannot use "_id" as key and use exclude_id simultaneously'
);
}

const result = collection.find({
[key]: id,
...(options?.exclude_id ? { _id: { $ne: options.exclude_id } } : {})
});
} as unknown as Parameters<typeof collection.find>[0]);

if (options?.caseInsensitive) {
result.collation({ locale: 'en', strength: 2 });
Expand Down

0 comments on commit a81a5f5

Please sign in to comment.