From 6de20c5cd14fe67eb89ce04083b494d53519557d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gunnar=20Farneb=C3=A4ck?= Date: Fri, 29 Aug 2025 11:38:22 +0200 Subject: [PATCH] Correctly set the variant bits of uuid1. --- stdlib/UUIDs/src/UUIDs.jl | 4 ++-- stdlib/UUIDs/test/runtests.jl | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/stdlib/UUIDs/src/UUIDs.jl b/stdlib/UUIDs/src/UUIDs.jl index 881e65b218d87..39381c5278fe6 100644 --- a/stdlib/UUIDs/src/UUIDs.jl +++ b/stdlib/UUIDs/src/UUIDs.jl @@ -74,8 +74,8 @@ function _build_uuid1(rng::AbstractRNG, timestamp::UInt64) # mask off clock sequence and node u &= 0x00000000000000003fffffffffffffff - # set the unicast/multicast bit and version - u |= 0x00000000000010000000010000000000 + # set the version, variant, and unicast/multicast bit + u |= 0x00000000000010008000010000000000 ts_low = timestamp & typemax(UInt32) ts_mid = (timestamp >> 32) & typemax(UInt16) diff --git a/stdlib/UUIDs/test/runtests.jl b/stdlib/UUIDs/test/runtests.jl index c6da441076ea8..27bcad1f20dc5 100644 --- a/stdlib/UUIDs/test/runtests.jl +++ b/stdlib/UUIDs/test/runtests.jl @@ -42,6 +42,15 @@ u7 = uuid7() @test uuid_version(u7) == 7 end +@testset "Extraction of variant bits" begin + # RFC 4122, section 4.1.1 + uuid_variant(u::UUID) = Int((u.value >> 62) & 0x3) + @test uuid_variant(u1) == 2 + @test uuid_variant(u4) == 2 + @test uuid_variant(u5) == 2 + @test uuid_variant(u7) == 2 +end + @testset "Parsing from string" begin @test u1 == UUID(string(u1)) == UUID(GenericString(string(u1))) @test u4 == UUID(string(u4)) == UUID(GenericString(string(u4)))