Commit 7edbee6c187460f656134199d8145b7f781f2c09

Authored by Dmitriy Zaporozhets
2 parents 4b6c93c1 314e4736

Merge branch 'strip_apostrophe_from_email_generated_username' into 'master'

Strip apostrophe from email generated username

Related to #1225
Fixes #1225
lib/gitlab/ldap/user.rb
@@ -50,7 +50,9 @@ module Gitlab @@ -50,7 +50,9 @@ module Gitlab
50 # we look for user by extracting part of their email 50 # we look for user by extracting part of their email
51 if !user && email && ldap_conf['allow_username_or_email_login'] 51 if !user && email && ldap_conf['allow_username_or_email_login']
52 uname = email.partition('@').first 52 uname = email.partition('@').first
53 - user = model.find_by(username: uname) 53 + # Strip apostrophes since they are disallowed as part of username
  54 + username = uname.gsub("'", "")
  55 + user = model.find_by(username: username)
54 end 56 end
55 57
56 user 58 user
lib/gitlab/oauth/user.rb
@@ -39,7 +39,9 @@ module Gitlab @@ -39,7 +39,9 @@ module Gitlab
39 # So we use part of email as username for new user 39 # So we use part of email as username for new user
40 # For LDAP, username is already set to the user's 40 # For LDAP, username is already set to the user's
41 # uid/userid/sAMAccountName. 41 # uid/userid/sAMAccountName.
42 - user.username = email.match(/^[^@]*/)[0] 42 + email_username = email.match(/^[^@]*/)[0]
  43 + # Strip apostrophes since they are disallowed as part of username
  44 + user.username = email_username.gsub("'", "")
43 end 45 end
44 46
45 user.save! 47 user.save!