From 7acdbc8448e8db86934035dc6f4d06950beda0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 16 Mar 2016 22:35:08 +0100 Subject: [PATCH] FIX: don't extract links from elided parts --- lib/pretty_text.rb | 4 ++-- spec/components/pretty_text_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 6dacab922d..3f30fbd3f5 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -328,8 +328,8 @@ module PrettyText def self.extract_links(html) links = [] doc = Nokogiri::HTML.fragment(html) - # remove href inside quotes - doc.css("aside.quote a").each { |l| l["href"] = "" } + # remove href inside quotes & elided part + doc.css("aside.quote a, .elided a").each { |l| l["href"] = "" } # extract all links from the post doc.css("a").each { |l| diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 94fe6437f0..d01cd51275 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -188,6 +188,10 @@ HTML expect(PrettyText.extract_links("\n").to_a).to be_empty end + it "doesn't extract links from elided parts" do + expect(PrettyText.extract_links("
cnn
\n").to_a).to be_empty + end + def extract_urls(text) PrettyText.extract_links(text).map(&:url).to_a end