Skip to content

[Validator] Add support for UUIDv6 in Uuid constraint #38332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CHANGELOG
```
* added the `Isin` constraint and validator
* added the `ULID` constraint and validator
* added support for UUIDv6 in `Uuid` constraint

5.1.0
-----
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Uuid extends Constraint
const V3_MD5 = 3;
const V4_RANDOM = 4;
const V5_SHA1 = 5;
const V6_SORTABLE = 6;

/**
* Message to display when validation fails.
Expand Down Expand Up @@ -74,6 +75,7 @@ class Uuid extends Constraint
self::V3_MD5,
self::V4_RANDOM,
self::V5_SHA1,
self::V6_SORTABLE,
];

public $normalizer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
* Strict validation will allow a UUID as specified per RFC 4122.
* Loose validation will allow any type of UUID.
*
* For better compatibility, both loose and strict, you should consider using a specialized UUID library like "ramsey/uuid" instead.
*
* @author Colin O'Dell <colinodell@gmail.com>
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see http://tools.ietf.org/html/rfc4122
* @see https://en.wikipedia.org/wiki/Universally_unique_identifier
* @see https://github.com/ramsey/uuid
*/
class UuidValidator extends ConstraintValidator
{
Expand All @@ -38,7 +35,7 @@ class UuidValidator extends ConstraintValidator

// Roughly speaking:
// x = any hexadecimal character
// M = any allowed version {1..5}
// M = any allowed version {1..6}
// N = any allowed variant {8, 9, a, b}

const STRICT_LENGTH = 36;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function getValidStrictUuids()
['456daefb-5aa6-41b5-8dbc-068b05a8b201'], // Version 4 UUID in lowercase
['456daEFb-5AA6-41B5-8DBC-068B05A8B201'], // Version 4 UUID in mixed case
['456daEFb-5AA6-41B5-8DBC-068B05A8B201', [Uuid::V4_RANDOM]],
['1eb01932-4c0b-6570-aa34-d179cdf481ae', [Uuid::V6_SORTABLE]],
];
}

Expand Down Expand Up @@ -145,7 +146,6 @@ public function getInvalidStrictUuids()
['216fff40-98d9-11e3-a5e2-0800200c9a6', Uuid::TOO_SHORT_ERROR],
['216fff40-98d9-11e3-a5e2-0800200c9a666', Uuid::TOO_LONG_ERROR],
['216fff40-98d9-01e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
['216fff40-98d9-61e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
['216fff40-98d9-71e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
['216fff40-98d9-81e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
['216fff40-98d9-91e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
Expand Down