summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-05-03 14:25:36 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-05-03 14:25:36 +0300
commit644b4c97e94a0d5009e0af659c8e3f3921fc336a (patch)
treeb5022d667779b30d43e711decc9d306371e1ab66 /lib
parent4291e28af72890ee4f9c0f306ba691ba84c3435d (diff)
parent0ae574007d2118fc6e291591121ceca2da6fc22e (diff)
downloadgitlab-ce-644b4c97e94a0d5009e0af659c8e3f3921fc336a.tar.gz
Merge pull request #8756 from zaburt/force_utf8_on_oauth_properties
add common method to force utf8 and force oauth properties to be utf8
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/o_auth/auth_hash.rb19
-rw-r--r--lib/gitlab/utils.rb4
2 files changed, 16 insertions, 7 deletions
diff --git a/lib/gitlab/o_auth/auth_hash.rb b/lib/gitlab/o_auth/auth_hash.rb
index ce52beec78e..0f16c925900 100644
--- a/lib/gitlab/o_auth/auth_hash.rb
+++ b/lib/gitlab/o_auth/auth_hash.rb
@@ -9,11 +9,11 @@ module Gitlab
end
def uid
- auth_hash.uid.to_s
+ Gitlab::Utils.force_utf8(auth_hash.uid.to_s)
end
def provider
- auth_hash.provider
+ Gitlab::Utils.force_utf8(auth_hash.provider.to_s)
end
def info
@@ -21,23 +21,28 @@ module Gitlab
end
def name
- (info.try(:name) || full_name).to_s.force_encoding('utf-8')
+ Gitlab::Utils.force_utf8((info.try(:name) || full_name).to_s)
end
def full_name
- "#{info.first_name} #{info.last_name}"
+ Gitlab::Utils.force_utf8("#{info.first_name} #{info.last_name}")
end
def username
- (info.try(:nickname) || generate_username).to_s.force_encoding('utf-8')
+ Gitlab::Utils.force_utf8(
+ (info.try(:nickname) || generate_username).to_s
+ )
end
def email
- (info.try(:email) || generate_temporarily_email).downcase
+ Gitlab::Utils.force_utf8(
+ (info.try(:email) || generate_temporarily_email).downcase
+ )
end
def password
- @password ||= Devise.friendly_token[0, 8].downcase
+ devise_friendly_token = Devise.friendly_token[0, 8].downcase
+ @password ||= Gitlab::Utils.force_utf8(devise_friendly_token)
end
# Get the first part of the email address (before @)
diff --git a/lib/gitlab/utils.rb b/lib/gitlab/utils.rb
index bd184c27187..d13fe0ef8a9 100644
--- a/lib/gitlab/utils.rb
+++ b/lib/gitlab/utils.rb
@@ -9,5 +9,9 @@ module Gitlab
def system_silent(cmd)
Popen::popen(cmd).last.zero?
end
+
+ def force_utf8(str)
+ str.force_encoding(Encoding::UTF_8)
+ end
end
end