From 3861bd2793a49d10e8584022f0dc9d7aed364f76 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 11 Apr 2017 15:13:21 +0800 Subject: [PATCH] FIX: Quotes should be ignored when parsing for onebox source. --- lib/excerpt_parser.rb | 6 +++++- spec/components/pretty_text_spec.rb | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb index 8c1938b06f7..b6547b59bb3 100644 --- a/lib/excerpt_parser.rb +++ b/lib/excerpt_parser.rb @@ -85,7 +85,11 @@ class ExcerptParser < Nokogiri::XML::SAX::Document end when "aside" - @in_quote = true unless @keep_onebox_source + attributes = Hash[*attributes.flatten] + + unless @keep_onebox_source && attributes['class'].include?('onebox') + @in_quote = true + end when 'article' if @keep_onebox_source && attributes.include?(['class', 'onebox-body']) @in_quote = true diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index d8535dcf192..8b0dfae4e92 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -289,15 +289,23 @@ HTML expect(PrettyText.excerpt(emoji_code, 100)).to eq(":heart:") end - it "should have an option to preserver onebox source" do - onebox = "\n\n\n" - expected = "meta.discourse.org" + context 'option ot preserve onebox source' do + it "should return the right excerpt" do + onebox = "\n\n\n" + expected = "meta.discourse.org" - expect(PrettyText.excerpt(onebox, 100, keep_onebox_source: true)) - .to eq(expected) + expect(PrettyText.excerpt(onebox, 100, keep_onebox_source: true)) + .to eq(expected) - expect(PrettyText.excerpt("#{onebox}\n \n \n \n\n\n #{onebox}", 100, keep_onebox_source: true)) - .to eq("#{expected}\n\n#{expected}") + expect(PrettyText.excerpt("#{onebox}\n \n \n \n\n\n #{onebox}", 100, keep_onebox_source: true)) + .to eq("#{expected}\n\n#{expected}") + end + + it 'should continue to strip quotes' do + expect(PrettyText.excerpt( + "boom", 100, keep_onebox_source: true + )).to eq("boom") + end end end