From 7cb76f7333ed452f89b63d56c97f8164f92debb4 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Sun, 20 Nov 2016 17:07:27 +0530 Subject: [PATCH] FIX: add rel noopener and noreferrer in addition to nofollow --- lib/pretty_text.rb | 4 ++-- spec/components/cooked_post_processor_spec.rb | 8 ++++---- spec/components/pretty_text_spec.rb | 2 +- spec/models/post_analyzer_spec.rb | 2 +- spec/models/post_spec.rb | 4 ++-- spec/models/user_profile_spec.rb | 12 ++++++------ 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 3814fd42a09..4ad0c96c3ca 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -261,11 +261,11 @@ module PrettyText whitelist.any?{|u| uri.host == u || uri.host.ends_with?("." << u)} # we are good no need for nofollow else - l["rel"] = "nofollow" + l["rel"] = "nofollow noopener noreferrer" end rescue URI::InvalidURIError, URI::InvalidComponentError # add a nofollow anyway - l["rel"] = "nofollow" + l["rel"] = "nofollow noopener noreferrer" end end end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 86810e5e597..8e95b49e83c 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -446,7 +446,7 @@ describe CookedPostProcessor do it "uses schemaless url for uploads" do cpp.optimize_urls - expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' + expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' end context "when CDN is enabled" do @@ -454,20 +454,20 @@ describe CookedPostProcessor do it "does use schemaless CDN url for http uploads" do Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") cpp.optimize_urls - expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' + expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' end it "does not use schemaless CDN url for https uploads" do Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com") cpp.optimize_urls - expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' + expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' end it "does not use CDN when login is required" do SiteSetting.login_required = true Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") cpp.optimize_urls - expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' + expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' end end diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 63577b90e9c..0105e0ae043 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -77,7 +77,7 @@ HTML end it "should inject nofollow in all user provided links" do - expect(PrettyText.cook('cnn')).to match(/nofollow/) + expect(PrettyText.cook('cnn')).to match(/nofollow noopener noreferrer/) end it "should not inject nofollow in all local links" do diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rb index 6bfe2f9cb82..8b549af7178 100644 --- a/spec/models/post_analyzer_spec.rb +++ b/spec/models/post_analyzer_spec.rb @@ -200,7 +200,7 @@ describe PostAnalyzer do it "ignores oneboxes" do post_analyzer = PostAnalyzer.new("Hello @Jake\n#{url}", default_topic_id) - post_analyzer.stubs(:cook).returns("

Hello @Jake
@Finn

") + post_analyzer.stubs(:cook).returns("

Hello @Jake
@Finn

") expect(post_analyzer.raw_mentions).to eq(['jake']) end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index e70f176d4af..0ce0ce9c576 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -812,7 +812,7 @@ describe Post do it "should add nofollow to links in the post for trust levels below 3" do post.user.trust_level = 2 post.save - expect(post.cooked).to match(/nofollow/) + expect(post.cooked).to match(/nofollow noopener noreferrer/) end it "when tl3_links_no_follow is false, should not add nofollow for trust level 3 and higher" do @@ -826,7 +826,7 @@ describe Post do SiteSetting.stubs(:tl3_links_no_follow).returns(true) post.user.trust_level = 3 post.save - expect(post.cooked).to match(/nofollow/) + expect(post.cooked).to match(/nofollow noopener noreferrer/) end end diff --git a/spec/models/user_profile_spec.rb b/spec/models/user_profile_spec.rb index 620b79e12b0..90918ffe154 100644 --- a/spec/models/user_profile_spec.rb +++ b/spec/models/user_profile_spec.rb @@ -121,8 +121,8 @@ describe UserProfile do it 'includes the link as nofollow if the user is not new' do user.user_profile.send(:cook) - expect(user_profile.bio_excerpt).to match_html("I love http://discourse.org") - expect(user_profile.bio_processed).to match_html("

I love http://discourse.org

") + expect(user_profile.bio_excerpt).to match_html("I love http://discourse.org") + expect(user_profile.bio_processed).to match_html("

I love http://discourse.org

") end it 'removes the link if the user is new' do @@ -160,8 +160,8 @@ describe UserProfile do created_user.save created_user.reload created_user.change_trust_level!(TrustLevel[2]) - expect(created_user.user_profile.bio_excerpt).to match_html("I love http://discourse.org") - expect(created_user.user_profile.bio_processed).to match_html("

I love http://discourse.org

") + expect(created_user.user_profile.bio_excerpt).to match_html("I love http://discourse.org") + expect(created_user.user_profile.bio_processed).to match_html("

I love http://discourse.org

") end end @@ -171,8 +171,8 @@ describe UserProfile do it 'includes the link with nofollow if the user is trust level 3 or higher' do user.trust_level = TrustLevel[3] user_profile.send(:cook) - expect(user_profile.bio_excerpt).to match_html("I love http://discourse.org") - expect(user_profile.bio_processed).to match_html("

I love http://discourse.org

") + expect(user_profile.bio_excerpt).to match_html("I love http://discourse.org") + expect(user_profile.bio_processed).to match_html("

I love http://discourse.org

") end end end