FIX: handle clicks counters in full quotes

approved
#1

FIX: handle clicks counters in full quotes

diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 705b43b..5ca50d5 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -106,10 +106,15 @@ class CookedPostProcessor
 
     return if previous.blank?
 
-    previous_text = Nokogiri::HTML::fragment(previous).text.strip
-    quoted_text = @doc.css("aside.quote:first-child blockquote").first&.text&.strip
+    # remove click counters
+    previous_doc = Nokogiri::HTML::fragment(previous)
+    previous_doc.css("span.clicks").remove
 
-    return if previous_text != quoted_text
+    previous_text = previous_doc.text.strip
+
+    quoted_text = @doc.css("aside.quote:first-child blockquote").first&.text&.strip || ""
+
+    return if previous_text.gsub(/(\s){2,}/, '\1') != quoted_text.gsub(/(\s){2,}/, '\1')
 
     quote_regexp = /\A\s*\[quote.+?\[\/quote\]/im
     quoteless_raw = @post.raw.sub(quote_regexp, "").strip
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index f99e0b9..c6f3759 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -1305,7 +1305,7 @@ describe CookedPostProcessor do
 
   end
 
-  context "remove direct reply full quote" do
+  context "full quote on direct reply" do
     fab!(:topic) { Fabricate(:topic) }
     let!(:post) { Fabricate(:post, topic: topic, raw: 'this is the "first" post') }
 
@@ -1384,6 +1384,23 @@ describe CookedPostProcessor do
       expect(reply.raw).to eq("and this is the third reply")
     end
 
+    it "works with click counters" do
+      post = Fabricate(:post,
+        topic: topic,
+        raw: "[Discourse](https://www.discourse.org) is amazing!",
+        cooked: %{<p><a href="https://www.discourse.org">Discourse <span class="badge badge-notification clicks" title="1 click">1</span></a> is amazing!</p>}
+      )
+
+      reply = Fabricate(:post,
+        topic: topic,
+        raw: "[quote]\n[Discourse](https://www.discourse.org) is amazing!\n[/quote]\nIt sure is :+1:"
+      )
+
+      CookedPostProcessor.new(reply).remove_full_quote_on_direct_reply
+
+      expect(reply.raw).to eq("It sure is :+1:")
+    end
+
   end
 
 end

GitHub sha: 7696b92c

REVERT: FIX: handle clicks counters in quotes
Followed Up #5

REVERT: FIX: handle clicks counters in quotes

Approved #7