From a5eb776a3724261da2f4e64db531c0b402fc71cc Mon Sep 17 00:00:00 2001 From: David Rothstein Date: Fri, 10 Nov 2017 00:22:04 -0500 Subject: [PATCH] Issue #2790923 by stefanos.petrakis, jenlampton, lokapujya, alexpott, biguzis, zniki.ru, dimaro, benjf, themic8, subhojit777, thtas, kpv, Noe_, Berdir, thijsvdanker, Cottser, dcam, jhodgdon: Allow + symbol in usernames --- CHANGELOG.txt | 1 + modules/user/user.module | 2 +- modules/user/user.test | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 81ec92424e16..2528efee95ca 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -7,6 +7,7 @@ Drupal 7.xx, xxxx-xx-xx (development version) addition: https://www.drupal.org/node/2857751). - Allowed callers of drupal_http_request() to optionally specify an explicit Host header. +- Allowed the + character to appear in usernames. Drupal 7.56, 2017-06-21 ----------------------- diff --git a/modules/user/user.module b/modules/user/user.module index d82c2fa9f100..2309aa92961f 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -637,7 +637,7 @@ function user_validate_name($name) { if (strpos($name, ' ') !== FALSE) { return t('The username cannot contain multiple spaces in a row.'); } - if (preg_match('/[^\x{80}-\x{F7} a-z0-9@_.\'-]/i', $name)) { + if (preg_match('/[^\x{80}-\x{F7} a-z0-9@+_.\'-]/i', $name)) { return t('The username contains an illegal character.'); } if (preg_match('/[\x{80}-\x{A0}' . // Non-printable ISO-8859-1 + NBSP diff --git a/modules/user/user.test b/modules/user/user.test index 0875e0ac7927..fb82c93c22a1 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -276,6 +276,7 @@ class UserValidationTestCase extends DrupalWebTestCase { 'foo@example.com' => array('Valid username', 'assertNull'), 'foo@-example.com' => array('Valid username', 'assertNull'), // invalid domains are allowed in usernames 'þòøÇߪř€' => array('Valid username', 'assertNull'), + 'foo+bar' => array('Valid username', 'assertNull'), // '+' symbol is allowed 'ᚠᛇᚻ᛫ᛒᛦᚦ' => array('Valid UTF8 username', 'assertNull'), // runes ' foo' => array('Invalid username that starts with a space', 'assertNotNull'), 'foo ' => array('Invalid username that ends with a space', 'assertNotNull'), @@ -2386,7 +2387,13 @@ class UserUserSearchTestCase extends DrupalWebTestCase { } function testUserSearch() { + // Verify that a user without 'administer users' permission cannot search + // for users by email address. Additionally, ensure that the username has a + // plus sign to ensure searching works with that. $user1 = $this->drupalCreateUser(array('access user profiles', 'search content', 'use advanced search')); + $edit['name'] = 'foo+bar'; + $edit['mail'] = $edit['name'] . '@example.com'; + user_save($user1, $edit); $this->drupalLogin($user1); $keys = $user1->mail; $edit = array('keys' => $keys);