Merge branch 'change/strip-whitespace-from-username-input#42637' into 'master'

Trim whitespace from input in the username/email form field

Closes #42637

See merge request gitlab-org/gitlab-ce!17020
This commit is contained in:
Rémy Coutable 2018-02-15 13:30:56 +00:00
commit 98e4d4083a
3 changed files with 14 additions and 1 deletions

View file

@ -249,7 +249,7 @@ class User < ActiveRecord::Base
def find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).find_by("lower(username) = :value OR lower(email) = :value", value: login.downcase)
where(conditions).find_by("lower(username) = :value OR lower(email) = :value", value: login.downcase.strip)
else
find_by(conditions)
end

View file

@ -0,0 +1,5 @@
---
title: Remove whitespace from the username/email sign in form field
merge_request: 17020
author: Peter lauck
type: changed

View file

@ -893,6 +893,14 @@ describe User do
end
end
describe '.find_for_database_authentication' do
it 'strips whitespace from login' do
user = create(:user)
expect(described_class.find_for_database_authentication({ login: " #{user.username} " })).to eq user
end
end
describe '.find_by_any_email' do
it 'finds by primary email' do
user = create(:user, email: 'foo@example.com')