Always trim the username before saving changes in the database

Fixes #4742
This commit is contained in:
Frédéric Guillot 2023-02-12 18:17:23 -08:00 committed by Frédéric Guillot
parent 5f3225bddc
commit bd8bcfbc37
2 changed files with 13 additions and 0 deletions

View File

@ -261,6 +261,10 @@ class UserModel extends Base
}
}
if (isset($values['username'])) {
$values['username'] = trim($values['username']);
}
$this->helper->model->removeFields($values, array('confirmation', 'current_password'));
$this->helper->model->resetFields($values, array('is_ldap_user', 'disable_login_form'));
$this->helper->model->convertNullFields($values, array('gitlab_id'));

View File

@ -394,4 +394,13 @@ class UserModelTest extends Base
$project = $projectModel->getById(1);
$this->assertEquals(0, $project['is_active']);
}
public function testTrimUsername()
{
$userModel = new UserModel($this->container);
$this->assertNotFalse($userModel->create(array('username' => 'test ')));
$this->assertNotEmpty($userModel->getByUsername('test'));
$this->assertEmpty($userModel->getByUsername('test '));
}
}