mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-26 03:01:14 +08:00
Posts with deeply nested html structures (ie. greater than Nokogiri's max tree depth) is causing a 500 error when viewing the drafts list route. When we can't process the excerpt for overly complex posts, we can just return a blank value which will still allows us to view and edit the draft as usual. Internal ref: /t/-/166042
30 lines
566 B
Ruby
Vendored
30 lines
566 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module PostItemExcerpt
|
|
def self.included(base)
|
|
base.attributes(:excerpt, :truncated)
|
|
end
|
|
|
|
def cooked
|
|
@cooked ||= object.cooked || PrettyText.cook(object.raw)
|
|
end
|
|
|
|
def excerpt
|
|
return nil unless cooked
|
|
|
|
@excerpt ||=
|
|
begin
|
|
PrettyText.excerpt(cooked, 300, keep_emoji_images: true)
|
|
rescue ArgumentError => e
|
|
e.message.include?("Document tree depth limit exceeded") ? "" : raise
|
|
end
|
|
end
|
|
|
|
def truncated
|
|
true
|
|
end
|
|
|
|
def include_truncated?
|
|
cooked.length > 300
|
|
end
|
|
end
|