From 314e4736e485ef00092ff7248503b439fac5c490 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 11 Jun 2014 17:06:28 +0200 Subject: [PATCH] Strip apostrophe from email generated usernames. --- lib/gitlab/ldap/user.rb | 4 +++- lib/gitlab/oauth/user.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index 01d8643..be3fcc4 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -50,7 +50,9 @@ module Gitlab # we look for user by extracting part of their email if !user && email && ldap_conf['allow_username_or_email_login'] uname = email.partition('@').first - user = model.find_by(username: uname) + # Strip apostrophes since they are disallowed as part of username + username = uname.gsub("'", "") + user = model.find_by(username: username) end user diff --git a/lib/gitlab/oauth/user.rb b/lib/gitlab/oauth/user.rb index d154bd8..c5be884 100644 --- a/lib/gitlab/oauth/user.rb +++ b/lib/gitlab/oauth/user.rb @@ -39,7 +39,9 @@ module Gitlab # So we use part of email as username for new user # For LDAP, username is already set to the user's # uid/userid/sAMAccountName. - user.username = email.match(/^[^@]*/)[0] + email_username = email.match(/^[^@]*/)[0] + # Strip apostrophes since they are disallowed as part of username + user.username = email_username.gsub("'", "") end user.save! -- libgit2 0.21.2