When creating a new user, Joomla allows spaces to be entered and saved as part of the username.
There is no validation message, and the whitespace remains part of the username.
6.1
The username should not accept spaces.
For example:
"Ahmad Moussa" → should be rejected
" AhmadMoussa" → should either be trimmed or rejected
"AhmadMoussa" → should be accepted
I think the username field should have proper validation to prevent whitespace from being used or stored.
For example, usernames such as "Ahmad Moussa", "AhmadMoussa " (with a trailing space), or " AhmadMoussa" (with a leading space) can be saved successfully. Joomla accepts and saves usernames containing spaces, including leading and trailing spaces.
Joomla 6.1.3
PHP: 8.4.23
Steps to reproduce
Go to Users → Manage in the Joomla Administrator.
Create a new user.
Enter a username such as "Ahmad Moussa"
Save the user.
The user is created successfully, and the username still contains the space.
Step to resolve
File:
libraries/src/Table/User.php
Find this:
preg_match('#[<>"'%;()&\\]|\.\./#', $this->username)
Change it to:
preg_match('#[\s<>"'%;()&\\]|\.\./#', $this->username)
So the complete condition becomes:
if (
preg_match('#[\s<>"'%;()&\\]|\.\./#', $this->username) || StringHelper::strlen($this->username) < 2
|| $filterInput->clean($this->username, 'TRIM') !== $this->username || StringHelper::strlen($this->username) > 150
) {
$this->setError(Text::sprintf('JLIB_DATABASE_ERROR_VALID_AZ09', 2));
return false;
}
I will create a pull request for this issue.
| Labels |
Added:
No Code Attached Yet
bug
|
||
Hi, I'd like to contribute to this issue. I'll investigate how username validation is handled and try to reproduce the problem. Could you share any guidance on the expected validation behavior or relevant test?