Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit af1ab9e

Browse filesBrowse files
bug #47499 [Uid][Validator] Stop to first ULID format violation (ogizanagi)
This PR was merged into the 5.4 branch. Discussion ---------- [Uid][Validator] Stop to first ULID format violation | Q | A | ------------- | --- | Branch? | 5.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | N/A | License | MIT | Doc PR | N/A Unlike the UUID validator, the ULID validator does not stop on the first violation raised, but continues adding a violation for each ULID format infringement. Which might make sense in some situations, but the same error message is set for each. In case of a string like `not-even-ulid-like`, you'll get 3 violations with the same message. IIMHO, 95% of the use-cases will consist of exposing the violation messages directly, so displaying 3 times the same message is unexpected. (getting different messages per violation type could be added as a new feature if needed) Commits ------- fdd73c7 [Validator][UID] Stop to first ULID format violation
2 parents 7369bc9 + fdd73c7 commit af1ab9e
Copy full SHA for af1ab9e

File tree

2 files changed

+5
-0
lines changed
Filter options

2 files changed

+5
-0
lines changed

‎src/Symfony/Component/Validator/Constraints/UlidValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/UlidValidator.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ public function validate($value, Constraint $constraint)
4848
->setParameter('{{ value }}', $this->formatValue($value))
4949
->setCode(26 > \strlen($value) ? Ulid::TOO_SHORT_ERROR : Ulid::TOO_LONG_ERROR)
5050
->addViolation();
51+
52+
return;
5153
}
5254

5355
if (\strlen($value) !== strspn($value, '0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz')) {
5456
$this->context->buildViolation($constraint->message)
5557
->setParameter('{{ value }}', $this->formatValue($value))
5658
->setCode(Ulid::INVALID_CHARACTERS_ERROR)
5759
->addViolation();
60+
61+
return;
5862
}
5963

6064
// Largest valid ULID is '7ZZZZZZZZZZZZZZZZZZZZZZZZZ'

‎src/Symfony/Component/Validator/Tests/Constraints/UlidValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/UlidValidatorTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function getInvalidUlids()
7878
['01ARZ3NDEKTSV4RRFFQ69G5FAVA', Ulid::TOO_LONG_ERROR],
7979
['01ARZ3NDEKTSV4RRFFQ69G5FAO', Ulid::INVALID_CHARACTERS_ERROR],
8080
['Z1ARZ3NDEKTSV4RRFFQ69G5FAV', Ulid::TOO_LARGE_ERROR],
81+
['not-even-ulid-like', Ulid::TOO_SHORT_ERROR],
8182
];
8283
}
8384

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.