Problem/Motivation
On the configuration page at /admin/config/people/passwords, the “Minimum password length” field is not required.
If the field is left empty, better_passwords_after_build() calls t() with a NULL value:
$element['#description'] .= '<br/>' . t(
'Passwords must be at least @num characters.',
['@num' => $config->get('length')] // <--- $config->get('length') can be NULL
);
This triggers the same core error as in:
https://www.drupal.org/project/drupal/issues/3554974
"TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238"
Steps to reproduce
- Install and enable Better Passwords.
- Go to /admin/config/people/passwords.
- Leave Minimum password length empty.
- Save configuration.
- Go to /admin/people/create and you get a WSOD
Proposed resolution
Wrap the code in a conditional check, the same way it is already done for the strength setting directly below it:
if (!empty($config->get('length'))) {
$element['#description'] .= '<br/>' . t(
'Passwords must be at least @num characters.',
['@num' => $config->get('length')]
);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | minimum_password_length_null.patch | 779 bytes | ritarshi_chakraborty |
| #2 | better_passwords-null_passed_to_t-3561441-2.patch | 848 bytes | fox mulder |
Issue fork better_passwords-3561441
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 #2
fox mulder commentedComment #3
ritarshi_chakraborty commentedI tried the patch on #2 and it resolves the error.
But I think it will be a better approach if we normalize the empty value in
submitForm.Comment #4
ritarshi_chakraborty commentedComment #5
fox mulder commented#4 doesn't solve the problem
Comment #6
kalash-j commentedComment #7
ritarshi_chakraborty commentedThat's weird :(
I applied the changes and the error seems to get resolved.
Comment #11
kalash-j commentedComment #12
anurag_nagar commented@kailash-j I have checked the MR and it seems to be working.
Comment #14
astonvictor commented