diff options
author | Rémy Coutable <remy@rymai.me> | 2016-01-18 12:35:30 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-01-18 14:58:16 +0100 |
commit | 2723dea6673b061dae2c266318727f9fd5aed8d4 (patch) | |
tree | 47094ea52ff38f2130eea8858c52237ff4309a0c /config/initializers | |
parent | f603f3b30bcd4303f07f87a0c6fa60697b2775fd (diff) | |
download | gitlab-ce-2723dea6673b061dae2c266318727f9fd5aed8d4.tar.gz |
Ensure Gravatar host looks like an actual hostfix-gravator-default-url
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/1_settings.rb | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index d625a909bf1..04a7c16ebde 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -9,13 +9,8 @@ class Settings < Settingslogic gitlab.port.to_i == (gitlab.https ? 443 : 80) end - # get host without www, thanks to http://stackoverflow.com/a/6674363/1233435 - def get_host_without_www(url) - url = CGI.escape(url) - uri = URI.parse(url) - uri = URI.parse("http://#{url}") if uri.scheme.nil? - host = uri.host.downcase - host.start_with?('www.') ? host[4..-1] : host + def host_without_www(url) + host(url).sub('www.', '') end def build_gitlab_ci_url @@ -87,6 +82,17 @@ class Settings < Settingslogic custom_port ] end + + # Extract the host part of the given +url+. + def host(url) + url = url.downcase + url = "http://#{url}" unless url.start_with?('http') + + # Get rid of the path so that we don't even have to encode it + url_without_path = url.sub(%r{(https?://[^\/]+)/?.*}, '\1') + + URI.parse(url_without_path).host + end end end @@ -228,7 +234,7 @@ Settings['gravatar'] ||= Settingslogic.new({}) Settings.gravatar['enabled'] = true if Settings.gravatar['enabled'].nil? Settings.gravatar['plain_url'] ||= 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon' Settings.gravatar['ssl_url'] ||= 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon' -Settings.gravatar['host'] = Settings.get_host_without_www(Settings.gravatar['plain_url']) +Settings.gravatar['host'] = Settings.host_without_www(Settings.gravatar['plain_url']) # # Cron Jobs |