-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: bson-4.7.2
When creating a UUID in js-bson, regex validation is performed that specifically requires a version 4 UUID format.
The regex used:
const VALIDATION_REGEX =
/^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i;
Why v4 and not a more generic format?
Notice specifically in the regext that "4" is required, as is "[89ab]"
e.g. 00000000-0000-4000-8000-000000000000
This means that a .NET Guid.Empty string value of "00000000-0000-0000-0000-000000000000" served to the js-bson is invalid and an error is thrown when one attempts to construct a UUID with it.
Node Team Notes:
AC
- Reduce the strictness of the regexp to allow any sequence of hex digits with or without dashes
- Remove bitwise validation from the isUint8Array section of UUID.isValid(uuid)
- Clarify documentation that new UUID() returns a version 4 UUID
- Add a test verifying that a UUID can be created from a sequence of bytes and from a string that are not version 4