diff options
author | Stan Hu <stanhu@gmail.com> | 2015-12-11 01:54:00 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-12-11 01:54:00 +0000 |
commit | 7bb8bb8520e0ce029011567cd700ae94099c9b96 (patch) | |
tree | 3724d549f31326061edd969802406829f7913258 | |
parent | 0d5d1f0e6fcd80fcf42dc9ab84ef3d146e47dc91 (diff) | |
parent | d8b3c3274c63d5fa62c441bac6e78a16e94422c3 (diff) | |
download | gitlab-ce-7bb8bb8520e0ce029011567cd700ae94099c9b96.tar.gz |
Merge branch 'auth_hash_fix' into 'master'
Expand character set of usernames created by Omniauth
When a user is created by Omniauth, Gitlab tries to assign the username based on the information provided in the auth hash. If no nickname is present, it uses the part of the email address before the @. This portion of the email address is run through the `parameterize` method, presumably to convert Unicode characters to ASCII.
`parameterize` strips out a number of characters that are valid in usernames. For example, `john.doe` is a valid Gitlab username, but parameterize will turn this into `john-doe`.
Instead of `parameterize`, this merge request uses `normalize` to convert non-ascii characters. This allows all acceptable characters to be used when creating a username from an email address.
See merge request !660
-rw-r--r-- | lib/gitlab/o_auth/auth_hash.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/o_auth/auth_hash_spec.rb | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/gitlab/o_auth/auth_hash.rb b/lib/gitlab/o_auth/auth_hash.rb index d94b104bbf8..ba31599432b 100644 --- a/lib/gitlab/o_auth/auth_hash.rb +++ b/lib/gitlab/o_auth/auth_hash.rb @@ -62,7 +62,7 @@ module Gitlab # Get the first part of the email address (before @) # In addtion in removes illegal characters def generate_username(email) - email.match(/^[^@]*/)[0].parameterize + email.match(/^[^@]*/)[0].mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/,'').to_s end def generate_temporarily_email(username) diff --git a/spec/lib/gitlab/o_auth/auth_hash_spec.rb b/spec/lib/gitlab/o_auth/auth_hash_spec.rb index a4f8b44e38e..8aaeb5779d3 100644 --- a/spec/lib/gitlab/o_auth/auth_hash_spec.rb +++ b/spec/lib/gitlab/o_auth/auth_hash_spec.rb @@ -14,7 +14,7 @@ describe Gitlab::OAuth::AuthHash, lib: true do let(:uid_raw) do "CN=Onur K\xC3\xBC\xC3\xA7\xC3\xBCk,OU=Test,DC=example,DC=net" end - let(:email_raw) { "onur.k\xC3\xBC\xC3\xA7\xC3\xBCk@example.net" } + let(:email_raw) { "onur.k\xC3\xBC\xC3\xA7\xC3\xBCk_ABC-123@example.net" } let(:nickname_raw) { "ok\xC3\xBC\xC3\xA7\xC3\xBCk" } let(:first_name_raw) { 'Onur' } let(:last_name_raw) { "K\xC3\xBC\xC3\xA7\xC3\xBCk" } @@ -66,7 +66,7 @@ describe Gitlab::OAuth::AuthHash, lib: true do before { info_hash.delete(:nickname) } it 'takes the first part of the email as username' do - expect(auth_hash.username).to eql 'onur-kucuk' + expect(auth_hash.username).to eql 'onur.kucuk_ABC-123' end end |