thyseus / yii-user-management

a user management module collection for the yii framework
186 stars 122 forks source link

UserModule username regex match #187

Closed kYem closed 10 years ago

kYem commented 10 years ago

I run into strange problem, that once i upload site on 1and1 servers, the username validation started to fail with message saying incorrect symbols, even if I written letters only. However on my local development machine Windows 8 + XAMP, PHP 5.5 it was working without any issues.

I found the reg expression defined in UserModule.php, which was /^[A-Za-z0-9_-\s]+$/u

As I have very limited knowledge of regex, I did some search on internet that breaked down the reg into this:

/^[A-Za-z0-9_-\s]+$/u
^ assert position at start of the string
[A-Za-z0-9_-\s]+ match a single character present in the list below
Quantifier: Between one and unlimited times, as many times as possible, 
giving back as needed [greedy]
A-Z a single character in the range between A and Z (case sensitive)
a-z a single character in the range between a and z (case sensitive)
0-9 a single character in the range between 0 and 9
_-\s a single character in the range between the following two characters
_ the literal character _
\s the literal character s (case sensitive)
$ assert position at end of the string
u modifier: unicode: Pattern strings are treated as UTF-16. 
Also causes escape sequences to match unicode characters

So the issues is the -\s as it does requires a character between and literal s. Removing \s from regex solved the issue leaving

/^[A-Za-z0-9_\-]+$/u 

while still allowing underscore and dash to be valid.

thyseus commented 10 years ago

I also have only basic regexp experience, but imo its o.k. to adjust the usernameRequirements your way. Will be changed in one of my next commits, thanks for reporting !