thibaultcha / lua-resty-jit-uuid

Fast and dependency-free UUID library for LuaJIT/ngx_lua
http://thibaultcha.github.io/lua-resty-jit-uuid/
MIT License
206 stars 40 forks source link

Invalid UUID #8

Closed subnetmarco closed 8 years ago

subnetmarco commented 8 years ago

The following UUID seems to be invalid 46c47c5e-d3b8-4c7a-cc5f-8d1fd989dde0:

local uuid = require "resty.jit-uuid"

uuid.is_valid("46c47c5e-d3b8-4c7a-cc5f-8d1fd989dde0") -- Is false, but why?

Why?

subnetmarco commented 8 years ago

I was also able to replicate this problem with 1c6284fc-0bdd-46c9-c672-2161d1e67ea4, e7b5c623-88f5-49bc-c929-eb3e21ef851f and 5bd6e192-022c-44e8-c432-2212fb705cb2.

Tieske commented 8 years ago

my 2cts; has to do with the uuid types. Previously it just generated random stuff (might be related to this; https://github.com/Tieske/uuid/pull/7 ).

The new validator also verifies the uuid type indication stored in the uuid. That's where it fails.

see https://github.com/thibaultcha/lua-resty-jit-uuid/blob/master/lib/resty/jit-uuid.lua#L73

Tieske commented 8 years ago

fix: either update all uuids, or relax the uuid validator

thibaultcha commented 8 years ago

Those are indeed invalid UUIDs according to RFC 4122 due to their variant field not being correctly set (for RFC 4122 only). Those uuids were probably generated from lua-uuid, which had that issue.

If not desired, one can use a custom UUID validator function (ideally relying on the same tricks this module is for optimized performance).