Generated `UUID` is not RFC compliant
- Dominant language
- C#
- Stars
- 9.7k
- Forks
- 538
- PR merge metrics
- No merged PRs in 30d
Description
The UUID that Bogus generates was not RFC compliant which was causing my tests to fail. I was able to workaround the issue by combining both of the solutions from issue #102 Determinism with Uuid
```csharp
var version = 4;
var guidBytes = this.Bytes(16);
// set the four most significant bits (bits 12 through 15) of the time_hi_and_version field to the appropriate 4-bit version number from Section 4.1.3 (step 8)
guidBytes[6] = (byte)((guidBytes[6] & 0x0F) | (version << 4));
// set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively (step 10)
guidBytes[8] = (byte)((guidBytes[8] & 0x3F) | 0x80);
// convert the resulting UUID to local byte order (step 13)
SwapByteOrder(guidBytes);
return new Guid(guidBytes);
static void SwapByteOrder(byte[] guid)
{
SwapBytes(guid, 0, 3);
SwapBytes(guid, 1, 2);
SwapBytes(guid, 4, 5);
SwapBytes(guid, 6, 7);
}
static void SwapBytes(byte[] guid, int left, int right)
{
byte temp = guid[left];
guid[left] = guid[right];
guid[right] = temp;
}
```
Contributor guide
Research direction
No file or test is named in the issue. Start by locating Bogus's UUID generation entry point and compare its output with the RFC requirements shown in the report, including version, variant, and byte order. Done means generated UUIDs are RFC-compliant and the relevant behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100