thamtech / yii2-uuid

UUID Helper and validator for Yii 2
Other
32 stars 0 forks source link

validation failed #6

Open svolga opened 3 years ago

svolga commented 3 years ago

Try to code:

$uuid = '59129aa7-86cb-9c60-0d1a-48b42abfcc3d';
$isValid = UuidHelper::isValid($uuid); 

It doesn't return true, but $uuid is uuid variable. Why?

tyler-ham commented 3 years ago

What code or library generated this string?

The 13th character represents the UUID version. In the case of your string, the 9 in 9c60 indicates UUID version 9. However, the UUID standard only defines versions 1 through 5. See UUID Versions in Wikipedia and RFC 4122 Section 4.1.3 Version.

The UUID validator here is checking to make sure that the version number is valid. In fact, it is the only check beyond making sure it has the right groupings of hexadecimal characters. The regular expression pattern used can be found in UuidValidator.php.

svolga commented 3 years ago

UUID was generated by postgrees function uuid_generate_v4() , this value also is not valid: a71df5c2-7db1-2d24-39f2-9f964de74ccf

tyler-ham commented 3 years ago

Technically speaking, I am open to relaxing the validator for UUIDv2. But I believe something strange is happening if both of these strings came from the same UUID generator. The first string (with the 9 in the version indicator) is clearly non-standard since there is no version 9 UUID. I also find it odd to see UUIDs with two different version indicators coming from the same generator. Typically, you'd select the appropriate UUID version for your application and stick with it. So I suspect something is not right with your implementation of uuid_generate_v4().

In a quick test of Postgres 13.1, the uuid_generate_v4() function from the uuid-ossp extension and the gen_random_uuid() function from the pgcrypto module both produce proper v4 UUIDs with a 4 in the 13th place every time.

What version of PostgreSQL are you using? What is the version of the uuid-ossp extension? Check for uuid-ossp in SELECT * FROM pg_available_extensions;. Also check the output of \df. See UUID Generator in PostgreSQL.

It would be good to know if your implementation of uuid_generate_v4() was in fact coming from the uuid-ossp extension. I found this statement to list functions by extension:

SELECT e.extname, ne.nspname AS extschema, p.proname, np.nspname AS proschema
FROM pg_catalog.pg_extension AS e
    INNER JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid)
    INNER JOIN pg_catalog.pg_proc AS p ON (p.oid = d.objid)
    INNER JOIN pg_catalog.pg_namespace AS ne ON (ne.oid = e.extnamespace)
    INNER JOIN pg_catalog.pg_namespace AS np ON (np.oid = p.pronamespace)
WHERE d.deptype = 'e'
ORDER BY 1, 3