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 ff10bca

Browse filesBrowse files
committed
bug #60270 [Validator] [WordCount] Treat 0 as one character word and do not exclude it (sidz)
This PR was squashed before being merged into the 7.2 branch. Discussion ---------- [Validator] [WordCount] Treat 0 as one character word and do not exclude it | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | no | License | MIT New **WordCount** validator has been introduced in the Symfony 7.2 but it has an issue and treats sentence ended on zero (0) as contains an empty string. This PR adds a callback function into `array_filter` to fix the issue. Commits ------- 6fded36 [Validator] [WordCount] Treat 0 as one character word and do not exclude it
2 parents c4ed8f0 + 6fded36 commit ff10bca
Copy full SHA for ff10bca

File tree

2 files changed

+2
-1
lines changed
Filter options

2 files changed

+2
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/WordCountValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function validate(mixed $value, Constraint $constraint): void
4444
$words = iterator_to_array($iterator->getPartsIterator());
4545

4646
// erase "blank words" and don't count them as words
47-
$wordsCount = \count(array_filter(array_map(trim(...), $words)));
47+
$wordsCount = \count(array_filter(array_map(trim(...), $words), fn ($word) => '' !== $word));
4848

4949
if (null !== $constraint->min && $wordsCount < $constraint->min) {
5050
$this->context->buildViolation($constraint->minMessage)

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/WordCountValidatorTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public static function provideValidValues()
8383
yield [new StringableValue('my ûtf 8'), 3];
8484
yield [null, 1]; // null should always pass and eventually be handled by NotNullValidator
8585
yield ['', 1]; // empty string should always pass and eventually be handled by NotBlankValidator
86+
yield ['My String 0', 3];
8687
}
8788

8889
public static function provideInvalidTypes()

0 commit comments

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