Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2014-05-30 19:09:31 +0400
committerMarin Jankovski <marin@gitlab.com>2014-05-30 19:09:31 +0400
commit4a03bbe4831399381a45cde7fd19ecfb67895bd4 (patch)
tree292355575d9f0656de5ea84d8461fcdd331202a6 /app/helpers
parent3910b5917c84875f94f8b15594e4c506a3de39cc (diff)
Add nofollow to all internal links.
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/application_helper.rb27
1 files changed, 20 insertions, 7 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 4a3b345bdfe..198ca76545c 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -233,16 +233,29 @@ module ApplicationHelper
end
def link_to(name = nil, options = nil, html_options = nil, &block)
- if html_options
- if html_options[:rel]
- html_options[:rel] << " noreferrer"
+ begin
+ uri = URI(options)
+ host = uri.host
+ absolute_uri = uri.absolute?
+ rescue URI::InvalidURIError, ArgumentError
+ host = nil
+ absolute_uri = nil
+ end
+
+ # Add "nofollow" only to external links
+ if host && host != Gitlab.config.gitlab.host && absolute_uri
+ if html_options
+ if html_options[:rel]
+ html_options[:rel] << " nofollow"
+ else
+ html_options.merge!(rel: "nofollow")
+ end
else
- html_options.merge(rel: "noreferrer")
+ html_options = Hash.new
+ html_options[:rel] = "nofollow"
end
- else
- html_options = Hash.new
- html_options[:rel] = "noreferrer"
end
+
super
end
end