summaryrefslogtreecommitdiff
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-02 11:52:03 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-02 11:52:03 +0000
commitf9dd1402807a42eec2b56354b0c2a7778433c7f5 (patch)
tree8433b584532cef10f6c8b03c1e0bb3bfe42b5ab0 /app/helpers/application_helper.rb
parent0d475208ac99b818d4063f73289390c578302459 (diff)
parent4a03bbe4831399381a45cde7fd19ecfb67895bd4 (diff)
downloadgitlab-ce-f9dd1402807a42eec2b56354b0c2a7778433c7f5.tar.gz
Merge branch 'add_noreferrer_to_all_links' into 'master'
Add nofollow to all external links Fixes #1224
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 5f07cdf448c..198ca76545c 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -231,4 +231,31 @@ module ApplicationHelper
content_tag(:i, nil, class: 'icon-spinner icon-spin') + text
end
end
+
+ def link_to(name = nil, options = nil, html_options = nil, &block)
+ 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 = Hash.new
+ html_options[:rel] = "nofollow"
+ end
+ end
+
+ super
+ end
end