Generated user name has spaces
pban02 - February 7, 2008 - 19:50
| Project: | User Import |
| Version: | 5.x-1.3 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Thanks for this great module - it makes it very easy to import data into profiles from a CSV file.
I am having one problem though - I imported a list of users and wanted to make their email address the login id, but the the generated username for an email like joe.smith@gmail.com ends up as
"joe smith@gmail com"
with spaces.
Is there any way to suppress this behaviour? I am using pathauto and set it to ignore characters like the dot.
Thanks in advance

#1
Looks like this is a problem with the function "_user_import_sanitise_username". It is running the following regex's:
// username cannot contain an illegal character$username = preg_replace('/[^a-zA-Z0-9@ ]/', ' ', $username);
// username cannot contain multiple spaces in a row
$username = preg_replace('/[ ]+/', ' ', $username);
However, spaces are not allowed in Drupal usernames (only periods, hyphens, and underscores). This should probably be updated to something like:
// username cannot contain an illegal character$username = preg_replace('/[^a-zA-Z0-9\.-_]/', '', $username);
// username should not contain multiple characters in a row
$username = preg_replace('/([\.\-_])[\.\-_]+/', '\\1', $username);
I'm not sure what the consensus is on multiple delimiters in a row, but my feeling is that you wouldn't want multiple periods, hyphens, and underscores in a row.