mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
FIX: blank cooked markdown could raise an exception in logs
Previously if somehow a user created a blank markdown document using tag tricks (eg `<p></p><p></p><p></p><p></p><p></p><p></p>`) and so on, we would completely strip the document down to blank on post process due to onebox hack. Needs a followup cause I am still unclear about the reason for empty p stripping and it can cause some unclear cases when we re-cook posts.
This commit is contained in:
parent
ab3bda6cd0
commit
7f3a30d79f
@ -23,7 +23,8 @@ class CookedPostProcessor
|
||||
@cooking_options[:topic_id] = post.topic_id
|
||||
@cooking_options = @cooking_options.symbolize_keys
|
||||
|
||||
@doc = Nokogiri::HTML::fragment(post.cook(post.raw, @cooking_options))
|
||||
cooked = post.cook(post.raw, @cooking_options)
|
||||
@doc = Nokogiri::HTML::fragment(cooked)
|
||||
@has_oneboxes = post.post_analyzer.found_oneboxes?
|
||||
@size_cache = {}
|
||||
|
||||
|
@ -116,7 +116,11 @@ module Oneboxer
|
||||
end
|
||||
|
||||
# strip empty <p> elements
|
||||
doc.css("p").each { |p| p.remove if p.children.empty? }
|
||||
doc.css("p").each do |p|
|
||||
if p.children.empty? && doc.children.count > 1
|
||||
p.remove
|
||||
end
|
||||
end
|
||||
|
||||
Result.new(doc, changed)
|
||||
end
|
||||
|
@ -1783,6 +1783,13 @@ describe CookedPostProcessor do
|
||||
expect(reply.raw).to eq(raw)
|
||||
end
|
||||
|
||||
it "does not generate a blank HTML document" do
|
||||
post = Fabricate(:post, topic: topic, raw: "<sunday><monday>")
|
||||
cp = CookedPostProcessor.new(post)
|
||||
cp.post_process
|
||||
expect(cp.html).to eq("<p></p>")
|
||||
end
|
||||
|
||||
it "works only on new posts" do
|
||||
Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post after")
|
||||
Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
|
||||
|
Loading…
Reference in New Issue
Block a user