mirror of
https://github.com/discourse/discourse.git
synced 2026-03-03 23:54:20 +08:00
The /drafts endpoint returns a 500 error when any draft contains HTML with excessive nesting depth or too many attributes per element. Nokogiri::HTML5.fragment raises ArgumentError when these limits are exceeded, and PrettyText.excerpt had no error handling for this. A previous fix in PostItemExcerpt only caught the tree depth variant, leaving the attributes limit unhandled, and only protecting one of the 13+ callers. Rescue ArgumentError around the Nokogiri::HTML5.fragment call in PrettyText.excerpt and return "" on failure. This is consistent with the existing blank-input guard and protects all callers at once. The now-redundant rescue in PostItemExcerpt is removed. Ref - t/173858
16 lines
441 B
Ruby
16 lines
441 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe PostItemExcerpt do
|
|
fab!(:post) { Fabricate(:post, raw: "abc " * 100) }
|
|
|
|
class DummyExcerptSerializer < ApplicationSerializer
|
|
include PostItemExcerpt
|
|
end
|
|
|
|
it "includes excerpt and truncated attributes" do
|
|
json = DummyExcerptSerializer.new(post, scope: Guardian.new, root: false).as_json
|
|
|
|
expect(json[:excerpt]).to be_present
|
|
expect(json[:truncated]).to eq(true)
|
|
end
|
|
end
|