Skip to content

[#15491] Fix allowEmpty value-list array support in AbstractValidator and Alpha empty-value handling#16904

Merged
niden merged 5 commits intophalcon:5.0.xfrom
niden-code:T15491-allowEmpty-value
Apr 23, 2026
Merged

[#15491] Fix allowEmpty value-list array support in AbstractValidator and Alpha empty-value handling#16904
niden merged 5 commits intophalcon:5.0.xfrom
niden-code:T15491-allowEmpty-value

Conversation

@niden
Copy link
Copy Markdown
Member

@niden niden commented Apr 22, 2026

Hello!

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG
  • I have created a PR for the documentation about this change

Small description of change:

#15491AbstractValidator::allowEmpty() value-list array support

AbstractValidator::allowEmpty() previously treated every array value of the allowEmpty option as a per-field map (['fieldName' => true/false]). This meant that the common pattern allowEmpty => [null, ''] (a list of values that should be skipped) silently fell back to false for all field names, so validation was never skipped.

The method now checks both forms:

  1. Per-field map (['fieldName' => true]) — checked first via isset $allowEmpty[$field], preserving the existing behaviour used by the Ip validator.
  2. Value list ([null, '']) — falls through to a strict === loop, consistent with Validation::preChecking(), so '0' is never silently treated as empty.

Three new Forms\Form\IsValidTest tests confirm that Form::isValid() correctly uses the stored entity (from the constructor or from bind()) and that allowEmpty=[null,''] skips validation for null/empty values from a bound entity with a null property.

#16200Alpha silently passes empty string when allowEmpty = false

preg_match("/[^[:alpha:]]/imu", "") returns 0 (no non-alpha chars in an empty string), so Alpha incorrectly returned true for empty/null values even when allowEmpty was explicitly set to false.

Alpha::validate() now adds an explicit guard: if the cast value is an empty string and getOption("allowEmpty") === false (explicitly set, not the default), it appends a message and returns false. When allowEmpty is not set the previous behaviour is preserved.

Thanks

@niden niden requested a review from Jeckerson April 22, 2026 13:51
@niden niden self-assigned this Apr 22, 2026
@niden niden added bug A bug report status: medium Medium 5.0 The issues we want to solve in the 5.0 release labels Apr 22, 2026
@niden niden marked this pull request as ready for review April 22, 2026 13:52
@niden niden merged commit 8b2ab93 into phalcon:5.0.x Apr 23, 2026
3 checks passed
@niden niden deleted the T15491-allowEmpty-value branch April 23, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants