From 7424d2fa5bd52b7f41ec4359bf80b1649b59706b Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 27 May 2015 15:39:08 -0400 Subject: Add ExternalLinkFilter to Markdown pipeline Forces a `rel="nofollow"` attribute on all external links. --- .../gitlab/markdown/external_link_filter_spec.rb | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/lib/gitlab/markdown/external_link_filter_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/markdown/external_link_filter_spec.rb b/spec/lib/gitlab/markdown/external_link_filter_spec.rb new file mode 100644 index 00000000000..c2ff4f80a42 --- /dev/null +++ b/spec/lib/gitlab/markdown/external_link_filter_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +module Gitlab::Markdown + describe ExternalLinkFilter do + def filter(html, options = {}) + described_class.call(html, options) + end + + it 'ignores elements without an href attribute' do + exp = act = %q(Ignore Me) + expect(filter(act).to_html).to eq exp + end + + it 'ignores non-HTTP(S) links' do + exp = act = %q(IRC) + expect(filter(act).to_html).to eq exp + end + + it 'skips internal links' do + internal = Gitlab.config.gitlab.url + exp = act = %Q(Login) + expect(filter(act).to_html).to eq exp + end + + it 'adds rel="nofollow" to external links' do + act = %q(Google) + doc = filter(act) + + expect(doc.at_css('a')).to have_attribute('rel') + expect(doc.at_css('a')['rel']).to eq 'nofollow' + end + end +end -- cgit v1.2.1