symfony / symfony

The Symfony PHP framework
https://symfony.com
MIT License
29.71k stars 9.44k forks source link

[uid] new UuidV6() produces uuid with upper case letters #45041

Closed bahadirbirsoz closed 2 years ago

bahadirbirsoz commented 2 years ago

Symfony version(s) affected

5.4 to 6.1

Description

UuidV6::generate method generates uid string representation with lower and upper cases. It is supposed to use only lower cases. The issue is at UuidV6::generate method.

How to reproduce

composer require symfony/uid php -a

php > include './vendor/autoload.php';
php > $uuid = new \Symfony\Component\Uid\UuidV6();
php > echo $uuid->toRfc4122();
1EC77985-E3D1-627C-81CC-057dc94ee45e     //  <- should have been all lowercase

php > $uuid = new \Symfony\Component\Uid\UuidV6('1EC77985-E3D1-627C-81CC-057dc94ee45e');
php > echo $uuid->toRfc4122();
1ec77985-e3d1-627c-81cc-057dc94ee45e       // this output is as expected.

Possible Solution

In the constructor, on line 30, instead of assigning generated value, parent::__construct can be called, as in the parent constructor, strtolower already exists.

Also, Uuid::V6 static method is already available for generation UuidV6 instance staticly. It is best to make this static::generate method private as it only generates a string representation of a uuid, and should be user internally.

Additional Context

According to RFC 4122

   Each field is treated as an integer and has its value printed as a
      zero-filled hexadecimal digit string with the most significant
      digit first.  The hexadecimal values "a" through "f" are output as
      lower case characters and are case insensitive on input.

According to https://www.itu.int/rec/T-REC-X.667/en

Software generating the hexadecimal representation of a UUID shall not use upper case letters. NOTE – It is recommended that the hexadecimal representation used in all human-readable formats be restricted to lower-case letters. Software processing this representation is, however, required to accept both upper and lower case letters as specified in 6.5.2.
fancyweb commented 2 years ago

I cannot reproduce the problem. Which PHP version do you use? Do you use the uuid extension or the polyfill? Do you have the problem with other uuid versions?

bahadirbirsoz commented 2 years ago

I cannot reproduce the problem. Which PHP version do you use? Do you use the uuid extension or the polyfill? Do you have the problem with other uuid versions?

Hello. I'm using PHP version 8.1.1 with Uuuid extension. I've just checkout uid 6.1 and reproduced it. I've also reproduced it with php 8.0 and polyfill as well.

plozmun commented 2 years ago

I can reproduce the error with php 8.1 in OSX but it seems that the problem is in extension. Try to generate uuid with the extension and check the result

// php uid.php
<?php

echo uuid_create(); // "D3151AC6-C9D9-4CD5-9C6C-DB2F2B999542"

Maybe you can open a issue in pecl repository https://github.com/php/pecl-networking-uuid

bahadirbirsoz commented 2 years ago

Yes, I can confirm that problem is in the extension. uuid_create with extension generates all uppercase string representation of uuid.

php > $uuid = \Symfony\Polyfill\Uuid\Uuid::uuid_create(1);
php > echo $uuid;
cb455324-783e-11ec-9197-cd5b40bb2813

Symfony polyfill creates all lowercase as expected. I have opened an issue on pecl repository.

https://github.com/php/pecl-networking-uuid/issues/3