Skip to content

Commit

Permalink
[release/9.0] fix guid version > 7 (#108351)
Browse files Browse the repository at this point in the history
* fix guid version > 7

* Update src/libraries/System.Runtime/tests/System.Runtime.Tests/System/GuidTests.cs

---------

Co-authored-by: kasperk81 <[email protected]>
  • Loading branch information
github-actions[bot] and kasperk81 authored Oct 16, 2024
1 parent 9305d7f commit 5d276d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libraries/System.Private.CoreLib/src/System/Guid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public Guid(string g)
/// <para>This corresponds to the most significant 4 bits of the 6th byte: 00000000-0000-F000-0000-000000000000.</para>
/// <para>See RFC 9562 for more information on how to interpret this value.</para>
/// </remarks>
public int Version => _c >>> 12;
public int Version => (ushort)_c >>> 12;

/// <summary>Creates a new <see cref="Guid" /> according to RFC 9562, following the Version 7 format.</summary>
/// <returns>A new <see cref="Guid" /> according to RFC 9562, following the Version 7 format.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ public static void NewGuid()
Assert.True((guid2.Variant == 0x8) || (guid2.Variant == 0x9) || (guid2.Variant == 0xA) || (guid2.Variant == 0xB));
}

[Fact]
public static void GuidVersionsAndVariants()
{
for (int i = 0; i <= 0xF; ++i)
{
Guid guid = new Guid($"00000000-0000-{i:X}000-{i:X}000-000000000000");

Assert.Equal(i, guid.Version);
Assert.Equal(i, guid.Variant);
}
}

[Fact]
public static void NewGuid_Randomness()
{
Expand Down

0 comments on commit 5d276d9

Please sign in to comment.