joomla/joomla-cms — pull request #4489 by joomdonation (2014-10-09 01:45:07+00:00)
Title: Fix Numeric usernames can start with a space issue

This pull request fix the issue #4481 Numeric usernames can start with a space. Basically, the username is validated using this line of code below in JTableUser class:

https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/table/user.php#L189

In this if command, the code trim($this->username) != $this->username doesn't work as expected.

In this case, when username only contains space and numeric characters, trim($this->username) != $this->username still return false (it seems because PHP "thinks" that " 123" and "123" are both number, so it is the same and the command return false instead of true as expected).

To fix this issue, we simply change != operator to !== and It works well.

How to test:

1. Try to register for an account using "Numeric usernames start with a space", for example " 123" (space + 123). You will see that Joomla still allows you to register using that username (unexpected behavior)

2. Apply this pull request

3. Try to register again. You will see that the username like that will be rejected