From 31d0998506aab82432e6df58e094af9a3450b3b2 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 28 Mar 2018 12:32:16 -0400 Subject: [PATCH] FIX: Don't allow links with no href --- app/models/post_analyzer.rb | 4 ++-- spec/models/post_analyzer_spec.rb | 5 +++++ spec/models/post_spec.rb | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb index ab8ec1903d2..5d069c72eb9 100644 --- a/app/models/post_analyzer.rb +++ b/app/models/post_analyzer.rb @@ -111,9 +111,9 @@ class PostAnalyzer return @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_s end diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rb index 937b47687cf..f7e20efc1e6 100644 --- a/spec/models/post_analyzer_spec.rb +++ b/spec/models/post_analyzer_spec.rb @@ -176,6 +176,11 @@ describe PostAnalyzer do expect(post_analyzer.link_count).to eq(0) end + it "returns links with href=''" do + post_analyzer = PostAnalyzer.new('Hello world', nil) + expect(post_analyzer.link_count).to eq(1) + end + it "finds links from markdown" do Oneboxer.stubs :onebox post_analyzer = PostAnalyzer.new(raw_post_one_link_md, default_topic_id) diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 9336d2ad1b7..2c1d237b8ae 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -410,7 +410,6 @@ describe Post do end it "finds links from HTML" do - expect(post_two_links.link_count).to eq(2) end