From 0f1629edb48b22fa587d7c32c141fbac0db927cd Mon Sep 17 00:00:00 2001 From: Jonas Meier Date: Thu, 27 May 2021 17:51:58 +0200 Subject: [PATCH] Fix cache for string IDs that have exactly 12 bytes * The method `isValid` from MongoDB just checks if a string has 12 bytes. But you could have a string ID which length=12 which would be unintentionally converted to an ObjectID which in returns causes an invalid cache miss. --- src/cache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache.js b/src/cache.js index 02aaffe..dd9d255 100644 --- a/src/cache.js +++ b/src/cache.js @@ -10,7 +10,7 @@ const stringToId = str => { return str } - if (ObjectId.isValid(str)) { + if (ObjectId.isValid(str) && new ObjectId(str) === str) { return new ObjectId(str) }