Problem/Motivation
The decimal check in PrimitiveTypeConstraintValidator ends its regular expression with $. In PHP, $ also matches before a final newline, so Drupal accepts "5\n" as a decimal.
Proposed resolution
- In
PrimitiveTypeConstraintValidator, end the decimal regular expression with\zinstead of$. - Add decimal rows to
PrimitiveTypeConstraintValidatorTest::provideTestValidate(), which has none today, including"5\n".
Issue fork drupal-3644214
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dries commentedI opened the MR and added a test that reproduces the bug. As expected, the tests failed.
Comment #4
dries commentedI already pushed a fix as it was simple: the decimal regex in
PrimitiveTypeConstraintValidatornow ends with\zinstead of$.https://www.php.net/manual/en/regexp.reference.escape.php explains that
\zmatches only at the end of the string, while$also matches before a final newline.That change did the trick. Setting to 'Needs review'.
Comment #5
ronaldtebrake commentedComment #6
ronaldtebrake commentedLooks good to me, this approach matches what I found while testing #3643182: Decimal JSON Schema accepts any string
AI disclosure: I used Claude Code (Opus 5.5) to help review the MR and run the tests.