summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2016-02-01 10:48:47 -0500
committerDavid Rothstein <drothstein@gmail.com>2016-02-01 10:48:47 -0500
commitf0b44bd9934251f383a0dc14920b71a52b40bec6 (patch)
treedab861aa69961c882057f9aabdd1e18a69a1e23a
parentd77ba6e7a8794aae5f46f3fed728c725b2e24e18 (diff)
downloadbrdo-f0b44bd9934251f383a0dc14920b71a52b40bec6.tar.gz
brdo-f0b44bd9934251f383a0dc14920b71a52b40bec6.tar.bz2
Issue #2251019 by PietM, jhodgdon, mgifford: User wildcard search doesn't work
-rw-r--r--modules/user/user.module8
-rw-r--r--modules/user/user.test14
2 files changed, 19 insertions, 3 deletions
diff --git a/modules/user/user.module b/modules/user/user.module
index 02950de3c..c33aa0982 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -958,6 +958,8 @@ function user_search_access() {
*/
function user_search_execute($keys = NULL, $conditions = NULL) {
$find = array();
+ // Escape for LIKE matching.
+ $keys = db_like($keys);
// Replace wildcards with MySQL/PostgreSQL wildcards.
$keys = preg_replace('!\*+!', '%', $keys);
$query = db_select('users')->extend('PagerDefault');
@@ -967,13 +969,13 @@ function user_search_execute($keys = NULL, $conditions = NULL) {
// and they don't need to be restricted to only active users.
$query->fields('users', array('mail'));
$query->condition(db_or()->
- condition('name', '%' . db_like($keys) . '%', 'LIKE')->
- condition('mail', '%' . db_like($keys) . '%', 'LIKE'));
+ condition('name', '%' . $keys . '%', 'LIKE')->
+ condition('mail', '%' . $keys . '%', 'LIKE'));
}
else {
// Regular users can only search via usernames, and we do not show them
// blocked accounts.
- $query->condition('name', '%' . db_like($keys) . '%', 'LIKE')
+ $query->condition('name', '%' . $keys . '%', 'LIKE')
->condition('status', 1);
}
$uids = $query
diff --git a/modules/user/user.test b/modules/user/user.test
index 97d23b44c..b9729c507 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -2230,6 +2230,20 @@ class UserUserSearchTestCase extends DrupalWebTestCase {
$this->drupalPost('search/user/', $edit, t('Search'));
$this->assertText($keys);
+ // Verify that wildcard search works.
+ $keys = $user1->name;
+ $keys = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
+ $edit = array('keys' => $keys);
+ $this->drupalPost('search/user/', $edit, t('Search'));
+ $this->assertText($user1->name, 'Search for username wildcard resulted in user name on page for administrative user.');
+
+ // Verify that wildcard search works for email.
+ $keys = $user1->mail;
+ $keys = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
+ $edit = array('keys' => $keys);
+ $this->drupalPost('search/user/', $edit, t('Search'));
+ $this->assertText($user1->name, 'Search for email wildcard resulted in user name on page for administrative user.');
+
// Create a blocked user.
$blocked_user = $this->drupalCreateUser();
$edit = array('status' => 0);