-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
None
-
None
-
None
-
None
-
None
-
None
-
None
When ObjectId.cacheHexString is enabled and an ObjectId is constructed from an uppercase or mixed-case 24-character hex string, the constructor caches the raw input verbatim. toHexString() then returns it as-is, violating its documented contract ("24 lowercase character hex string") and breaking equals(), whose string and ObjectId-like paths lowercase the other value and compare it against this.toHexString().
Repro:
ObjectId.cacheHexString = true; const oid = new ObjectId('AAAAAAAAAAAAAAAAAAAAAAAA'); oid.toHexString(); // 'AAAA...' (expected lowercase) oid.equals('aaaaaaaaaaaaaaaaaaaaaaaa'); // false (expected true)
Fix: cache workingId.toLowerCase() in the string-constructor branch of src/objectid.ts (the id setter already normalizes via ByteUtils.toHex). Surfaced by Copilot review on PR #893.