Skip to content

[Validator] [WordCount] Treat 0 as one character word and do not exclude it #60270

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
Apr 27, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function validate(mixed $value, Constraint $constraint): void
$words = iterator_to_array($iterator->getPartsIterator());

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

if (null !== $constraint->min && $wordsCount < $constraint->min) {
$this->context->buildViolation($constraint->minMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static function provideValidValues()
yield [new StringableValue('my ûtf 8'), 3];
yield [null, 1]; // null should always pass and eventually be handled by NotNullValidator
yield ['', 1]; // empty string should always pass and eventually be handled by NotBlankValidator
yield ['My String 0', 3];
}

public static function provideInvalidTypes()
Expand Down
Loading