FIX: embedding topics would fail with some HTML

When truncating content we try to search for first paragraph, if HTML had
no P it would fallback to first div which may have nested elements.
This commit is contained in:
Sam Saffron 2019-08-07 12:45:55 +10:00
parent 3c44e54c3f
commit 2408d55551
2 changed files with 11 additions and 1 deletions

View File

@ -227,7 +227,7 @@ class TopicEmbed < ActiveRecord::Base
return result unless result.blank?
# If there is no first paragaph, return the first div (onebox)
doc.css('div').first
doc.css('div').first.to_s
end
def self.expanded_for(post)

View File

@ -105,6 +105,16 @@ describe TopicEmbed do
expect(post.raw).to include(long_content)
end
it 'looks at first div when there is no paragraph' do
no_para = "<div><h>testing it</h></div>"
SiteSetting.embed_truncate = true
post = TopicEmbed.import(user, url, title, no_para)
expect(post.raw).to include("testing it")
end
end
end