Problem/Motivation
Searching for weight: in all of Drupal core finds 21 matches.
All 21 look like this:
weight:
type: integer
label: 'Weight'
👆 That means an arbitrary integer is allowed. We should add validation.
(See #2920678: Add config validation for the allowed characters of machine names for a similar issue. Note: this blocks #3379725: Make Block config entities fully validatable and many other issues.)
Steps to reproduce
N/A
Proposed resolution
I think that at a minimum, this should be restricted to the largest supported 32-bit integers. Per https://www.php.net/manual/en/reserved.constants.php, that's -2147483648 (PHP_INT_MIN on 32-bit systems) and 2147483647 (PHP_INT_MAX on 32-bit systems).
Note this also matches the supported (signed) integer value ranges in MySQL and MariaDB. Which makes sense, because those use 32 bits of storage.
IOW: "32-bits ought to be enough for expressing weights in Drupal".
Remaining tasks
None.
User interface changes
None.
API changes
API addition: weight config schema data type
Data model changes
None.
Release notes snippet
None.
Issue fork drupal-3426309
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
wim leersMR created.
CR created: https://www.drupal.org/node/3426319.
This hard-blocks #3379725: Make Block config entities fully validatable but soft-blocks many more issues, for example #3421946: [PP-2] Make FilterFormat config entities fully validatable, #2920441: Add config validation for workflow entities and many other yet-to-be-created issues.
Weights are pervasive, so standardizing them on a single way to validate them would instantly help much more config reach a higher degree of validatability. Hence bumping to priority.
Comment #4
smustgrave commentedRerunning the failing javascript test. All green now
The weight type makes a lot of sense, actually been eyeing this ticket for my contrib modules to get validatable.
Appears all instances have label: Weight that was of type integer has been replaced
Change has test coverage too, can be seen https://git.drupalcode.org/issue/drupal-3426309/-/jobs/1015331
Comment #5
wim leersComment #7
catchThe PHP_MAX_INT was slightly alarming, but what else could we set it to. Looks good. Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!