Skip to content

Conversation

@GunnarFarneback
Copy link
Contributor

The uuid1 function has been incorrect since it was added to Base in Julia 0.4, in that it fails to set the variant bits specified in section 4.1.1 of RFC 4122. This is fixed in this PR and a test is added.

The other implemented uuid versions are doing this correctly.

@nsajko
Copy link
Member

nsajko commented Aug 29, 2025

Error in testset UUIDs:
Test Failed at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-P2C257CXGN.0/build/default-honeycrisp-P2C257CXGN-0/julialang/julia-master/julia-8fc4e1cd92/share/julia/stdlib/v1.13/UUIDs/test/runtests.jl:48
  Expression: uuid_version(u1) == 2
   Evaluated: 1 == 2
Error in testset UUIDs:
Test Failed at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-P2C257CXGN.0/build/default-honeycrisp-P2C257CXGN-0/julialang/julia-master/julia-8fc4e1cd92/share/julia/stdlib/v1.13/UUIDs/test/runtests.jl:49
  Expression: uuid_version(u4) == 2
   Evaluated: 4 == 2
Error in testset UUIDs:
Test Failed at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-P2C257CXGN.0/build/default-honeycrisp-P2C257CXGN-0/julialang/julia-master/julia-8fc4e1cd92/share/julia/stdlib/v1.13/UUIDs/test/runtests.jl:50
  Expression: uuid_version(u5) == 2
   Evaluated: 5 == 2
Error in testset UUIDs:
Test Failed at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-P2C257CXGN.0/build/default-honeycrisp-P2C257CXGN-0/julialang/julia-master/julia-8fc4e1cd92/share/julia/stdlib/v1.13/UUIDs/test/runtests.jl:51
  Expression: uuid_version(u7) == 2
   Evaluated: 7 == 2
ERROR: LoadError: Test run finished with errors

@GunnarFarneback
Copy link
Contributor Author

Copy and paste error, should be fixed now.

Copy link
Member

@StefanKarpinski StefanKarpinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me as-is, but if we wanted to define a uuid_variant function that's a bit more general, we could do this:

"""
    uuid_variant(u::UUID) :: Symbol

Return UUID variant as one of the following symbols:
- `:NCS`
- `:RFC4122`
- `:Microsoft`
- `:Reserved`
"""
function uuid_variant(u::UUID)
    v = UInt8((u.value >> 61) & 0x7)
    v  0x3 ? :NCS_compat :
    v  0x5 ? :RFC4122    :
    v  0x6 ? :Microsoft  :
              :Reserved
end

Asking about the version seems to only make sense if the variant is RFC4122.

@GunnarFarneback
Copy link
Contributor Author

Better do that in a separate PR since this is a pure bugfix, which can be backported.

@DilumAluthge DilumAluthge added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 bugfix This change fixes an existing bug labels Aug 29, 2025
@StefanKarpinski StefanKarpinski merged commit a776445 into JuliaLang:master Aug 30, 2025
12 checks passed
KristofferC pushed a commit that referenced this pull request Sep 1, 2025
@GunnarFarneback GunnarFarneback deleted the uuid1_variant_bits branch September 1, 2025 06:57
KristofferC pushed a commit that referenced this pull request Sep 2, 2025
@DilumAluthge DilumAluthge mentioned this pull request Sep 9, 2025
59 tasks
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Sep 11, 2025
KristofferC pushed a commit that referenced this pull request Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 bugfix This change fixes an existing bug stdlib Julia's standard library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants