pure-uuid icon indicating copy to clipboard operation
pure-uuid copied to clipboard

Malformed UUIDs v4

Open bennycode opened this issue 4 years ago • 4 comments

I have been using new UUID(4).format() and noticed that it generates some invalid / malformed UUIDs.

A proper UUID v4 looks like this:

  • b277311c-dd9c-45c1-a041-2f78c5fd066e (32 chars total, 4 dashes)

But I somehow received the following UUIDs:

  • 298f8a6b-3e-1c4-4bba-9488-8f4b233e63e7 (34 chars total, 5 dashes)
  • 15ee-168da--20c6-4c1f0-9a2b--2806bf323e706 (36 chars total, 6 dashes)

Is it possible that UUID(4).format() generates UUIDs with too many dashes (with 1 extra char per extra dash)? Can this library be affected by a sign problem?

bennycode avatar Jun 19 '20 13:06 bennycode

I cannot reproduce your problem:

$ cat test.js 
const UUID = require("./")
for (let i = 0; i < 100000; i++)
     console.log(new UUID(4).format())
$ node test.js | egrep -v '^.{36}$' 

Even with 100K generated UUIDs it was always 36 characters in total...

rse avatar Jun 19 '20 13:06 rse

We replaced the library without other changes and the issue went away.

Yserz avatar Jun 25 '20 08:06 Yserz

@rse we experienced the described problem only with some users but reliably. Is it possible that your algorithm uses system specific values for its computation?

bennycode avatar Jun 25 '20 08:06 bennycode