FIX: Don't allow links with no href

This commit is contained in:
Robin Ward 2018-03-28 12:32:16 -04:00
parent 9e7d5a3cdf
commit 31d0998506
3 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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('<a href="">Hello world</a>', 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)

View File

@ -410,7 +410,6 @@ describe Post do
end
it "finds links from HTML" do
expect(post_two_links.link_count).to eq(2)
end