A platform for community discussion. Free, open, simple.
FIX: respect nofollow settings for onebox links
Arpit Jalanb75b6de98201
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 05d5924753e..4b8aa8c5f7a 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -454,6 +454,10 @@ class CookedPostProcessorimg.parent["style"] = "--aspect-ratio:#{width}/#{height};"endend++ if @cooking_options[:omit_nofollow] || !SiteSetting.add_rel_nofollow_to_user_content+ @doc.css(".onebox-body a, .onebox a").each { |a| a.remove_attribute("rel") }+ endenddef optimize_urlsdiff --git a/lib/pretty_text.rb b/lib/pretty_text.rbindex 0e838279712..4e2fc4e81e3 100644--- a/lib/pretty_text.rb+++ b/lib/pretty_text.rb@@ -273,6 +273,7 @@ module PrettyTexturi.host.ends_with?("." << site_uri.host) ||whitelist.any? { |u| uri.host == u || uri.host.ends_with?("." << u) }# we are good no need for nofollow+ l.remove_attribute("rel")elsel["rel"] = "nofollow noopener"enddiff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex 2f60a6e46f8..103bbc4f799 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -490,6 +490,24 @@ describe CookedPostProcessor doendend+ context ".post_process_oneboxes removes nofollow if add_rel_nofollow_to_user_content is disabled" do+ let(:post) { build(:post_with_youtube, id: 123) }+ let(:cpp) { CookedPostProcessor.new(post, invalidate_oneboxes: true) }++ before do+ SiteSetting.add_rel_nofollow_to_user_content = false+ Oneboxer.expects(:onebox)+ .with("http://www.youtube.com/watch?v=9bZkp7q19f0", invalidate_oneboxes: true, user_id: nil, category_id: post.topic.category_id)+ .returns('<aside class="onebox"><a href="https://www.youtube.com/watch?v=9bZkp7q19f0" rel="nofollow noopener">GANGNAM STYLE</a></aside>')+ cpp.post_process_oneboxes+ end++ it "removes nofollow noopener from links" do+ expect(cpp).to be_dirty+ expect(cpp.html).to match_html '<aside class="onebox"><a href="https://www.youtube.com/watch?v=9bZkp7q19f0">GANGNAM STYLE</a></aside>'+ end+ end+context ".post_process_oneboxes with square image" doit "generates a onebox-avatar class" do