rse / pure-uuid

Pure JavaScript Based Universally Unique Identifiers (UUID)

Home Page:https://www.npmjs.com/package/pure-uuid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Malformed UUIDs v4

bennycode opened this issue · 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?

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...

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

@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?