A platform for community discussion. Free, open, simple.
FIX: Don't allow links with no href
Robin Ward31d0998506aa
diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rbindex ab8ec1903d2..5d069c72eb9 100644--- a/app/models/post_analyzer.rb+++ b/app/models/post_analyzer.rb@@ -111,9 +111,9 @@ class PostAnalyzerreturn @raw_links if @raw_links.present?@raw_links = []- cooked_stripped.css("a[href]").each do |l|+ cooked_stripped.css("a").each do |l|# Don't include @mentions in the link count- next if l['href'].blank? || link_is_a_mention?(l)+ next if link_is_a_mention?(l)@raw_links << l['href'].to_senddiff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rbindex 937b47687cf..f7e20efc1e6 100644--- a/spec/models/post_analyzer_spec.rb+++ b/spec/models/post_analyzer_spec.rb@@ -176,6 +176,11 @@ describe PostAnalyzer doexpect(post_analyzer.link_count).to eq(0)end+ it "returns links with href=''" do+ post_analyzer = PostAnalyzer.new('<a href="">Hello world</a>', nil)+ expect(post_analyzer.link_count).to eq(1)+ end+it "finds links from markdown" doOneboxer.stubs :oneboxpost_analyzer = PostAnalyzer.new(raw_post_one_link_md, default_topic_id)diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 9336d2ad1b7..2c1d237b8ae 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -410,7 +410,6 @@ describe Post doendit "finds links from HTML" do-expect(post_two_links.link_count).to eq(2)end