Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7554478

Browse files
committed
[Validator][ULID] Stop to first violation
1 parent 8b17626 commit 7554478

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

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

Lines 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

Lines 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)