diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb index 03485ad812e..af38f8635db 100644 --- a/lib/excerpt_parser.rb +++ b/lib/excerpt_parser.rb @@ -63,6 +63,8 @@ class ExcerptParser < Nokogiri::XML::SAX::Document when "div", "span" if attributes.include?(["class", "excerpt"]) + @excerpt = "" + @current_length = 0 @start_excerpt = true end # Preserve spoilers diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 4becd6eb60c..51ebd41ac43 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -190,12 +190,22 @@ describe PrettyText do PrettyText.excerpt(nil,100).should == '' end - it "handles span excerpt" do + it "handles span excerpt at the beginning of a post" do PrettyText.excerpt("hi test",100).should == 'hi' post = Fabricate(:post, raw: "hi test") post.excerpt.should == "hi" end + it "handles span excerpt that starts before the max length" do + text = "123456789 123456789 12345679 123456789 123456789 " + + "as long as span starts before max length of the " + + "the specified excerpt" + + "of the post will be used" + PrettyText.excerpt(text, 100).should == 'the specified excerpt' + post = Fabricate(:post, raw: text) + post.excerpt.should == 'the specified excerpt' + end + end describe "strip links" do