- Issue created by @murz
- π¦π²Armenia murz Yerevan, Armenia
The validation error appears in the
core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidator.php
file when it uses the functionfilter_var()
having the empty string (''
) in the$value
:if ($typed_data instanceof IntegerInterface && filter_var($value, FILTER_VALIDATE_INT) === FALSE) { $valid = FALSE; }
So, seems the easiest solution is to cast the value to the "int" type (and the same - for float), something like this:
if ($typed_data instanceof IntegerInterface && filter_var((int) $value, FILTER_VALIDATE_INT) === FALSE) { $valid = FALSE; }
I prepared a MR https://git.drupalcode.org/project/drupal/-/merge_requests/11998 with this fix, which resolves the issue. But not sure that this is the correct fix, and seems we should cover this with tests, so marking the issue as "Needs Review" to get the feedback.
- πΊπΈUnited States smustgrave
Thanks for reporting and getting an MR already. Appears to have a pipeline failure.
Also can we get a test case showing the problem as a next step.
Thanks
- Merge request !12013Draft: Issue #3522116: Failing tests only [Do not merge!] β (Closed) created by murz
- π¦π²Armenia murz Yerevan, Armenia
I created a separate MR https://git.drupalcode.org/project/drupal/-/merge_requests/11998 representing the issue and the failing test.
And updated the MR to fix the issue and make the same test pass.
Please review. - πΊπΈUnited States smustgrave
Removing tests tag after running test-only feature https://git.drupalcode.org/issue/drupal-3522116/-/jobs/5129880
Change seems straight forward and didn't break existing tests so don't think have to worry about breaking other stuff.
LGTM
- π³πΏNew Zealand quietone
I have only read the title here and tagging for a title update.
The title should be a description of what is being fixed or improved. The title is used as the git commit message so it should be meaningful and concise. See List of issue fields β .
- π¦π²Armenia murz Yerevan, Armenia
I updated the issue title, please check if the name suits the rules now.
- π¦π²Armenia murz Yerevan, Armenia
Attach a static patch file with those changes, to make it possible to use in composer until π GitLab Merge Requests Unable to Generate Incremental Patch Files Active is resolved.
- πͺπΈSpain penyaskito Seville π, Spain πͺπΈ, UTC+2 πͺπΊ
How is that casted back to a numeric then? Do we need to use
int|string
everywhere?
I'm not sure this is the way forward. I'd prefer it to be nullable than allowing a string.