Skip to content

[FrameworkBundle][Uid] UuidV1 case depends on uuid installed or not #57878

@smnandre

Description

@smnandre

Symfony version(s) affected

6.4, 7.0, 7.1 (?)

Description

I found a strange bug while running the FrameworkBundle tests locally

Symfony\Bundle\FrameworkBundle\Tests\Functional\UidTest::testArgumentValueResolverEnabled
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'0aa49ee6-4de7-11ef-9275-ca8c1eeac807'
+'0AA49EE6-4DE7-11EF-9275-CA8C1EEAC807'
// Symfony/Bundle/FrameworkBundle/Tests/Functional/UidTest.php

$client->request('GET', '/1/uuid-v1/'.$uuidV1 = new UuidV1());
$this->assertSame((string) $uuidV1, $client->getResponse()->getContent());

It took me some time to realize my local PHP still had the "uid" extension installed.

So the problem comes down to this in

// Symfony/Component/Uid/UuidV1.php

public function __construct(?string $uuid = null)
{
    if (null === $uuid) {
        $this->uid = uuid_create(static::TYPE);
    } else {
        parent::__construct($uuid, true);
    }
}

uuid_create from the Symfony polyfill only generates lowercase strings, but the uuid_create from the extension does not.

So when the ArgumentResolver works, as it set the $uuid arguments, the parent::__construct is called, where a strtolower is applied to $this-uid

How to reproduce

Install the uuid extension and run the FrameworkBundle functional tests

Possible Solution

Add a strtolower (or any optimized strtr) in the UuiV1 constructor ? (if so i'll open a PR)

Or do you think we need to ensure all uid values are stored internally in lowercase ?

...

Or this should not be considered a bug at all ?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions