Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When the maximum length of a text field is set to less than 6 the _text_devel_generate()
function will throw an error:
Warning: mt_rand(): max(0) is smaller than min(1) in _text_devel_generate()
This is because the max value is the max_length
divided by six, implicitly cast to an int.
Proposed resolution
Use the ceil() function to ensure the division provides a max of at least 1 on max_lengths greater than 0.
Remaining tasks
Patch needs review.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
devel_generate-small-max-length-bug.patch | 745 bytes | JvE | |
|
Comments
Comment #2
JvE CreditAttribution: JvE at One Shoe commentedNote that the Drupal 8 version doesn't have this bug.
There it actually moved to drupal core for which I created a separate issue: #2750925: Text item sample generation fails if max length < 3
Comment #3
JvE CreditAttribution: JvE at One Shoe commentedComment #4
jimmyko CreditAttribution: jimmyko as a volunteer commentedI can confirm this issue and manually tested the patch. It is working on Drupal 7.52 with devel-7.x-1.5
Comment #6
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commented