From 7be19db42fd51da23b1ef658263897213b624500 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Wed, 8 Jun 2016 02:02:55 -0500 Subject: Set target="_blank" for external links --- spec/features/markdown_spec.rb | 10 ++++++++++ spec/fixtures/markdown.md.erb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb index 7663d193354..cabccdacf87 100644 --- a/spec/features/markdown_spec.rb +++ b/spec/features/markdown_spec.rb @@ -173,10 +173,20 @@ describe 'GitLab Markdown', feature: true do expect(link.attr('rel')).to include('noreferrer') end + it 'adds _blank to target attribute for external links' do + link = doc.at_css('a:contains("Google")') + expect(link.attr('target')).to match('_blank') + end + it 'ignores internal link' do link = doc.at_css('a:contains("GitLab Root")') expect(link.attr('rel')).not_to match 'nofollow' end + + it 'does not set _blank to target attribute for internal links' do + link = doc.at_css('a:contains("GitLab Root")') + expect(link.attr('target')).not_to match '_blank' + end end end diff --git a/spec/fixtures/markdown.md.erb b/spec/fixtures/markdown.md.erb index 34ce7c4f033..c75d28d9801 100644 --- a/spec/fixtures/markdown.md.erb +++ b/spec/fixtures/markdown.md.erb @@ -136,7 +136,7 @@ But it shouldn't autolink text inside certain tags: ### ExternalLinkFilter -External links get a `rel="nofollow"` attribute: +External links get a `rel="nofollow noreferrer"` and `target="_blank"` attributes: - [Google](https://google.com/) - [GitLab Root](<%= Gitlab.config.gitlab.url %>) -- cgit v1.2.1