diff --git a/actiontext/CHANGELOG.md b/actiontext/CHANGELOG.md index 0a0a3e2521..e8e4a711f7 100644 --- a/actiontext/CHANGELOG.md +++ b/actiontext/CHANGELOG.md @@ -1,2 +1,5 @@ +* Only sanitize `content` attribute when present in attachments. + + *Petrik de Heus* Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/actiontext/CHANGELOG.md) for previous changes. diff --git a/actiontext/lib/action_text/content.rb b/actiontext/lib/action_text/content.rb index 3c07dad4f0..6de1fa45cf 100644 --- a/actiontext/lib/action_text/content.rb +++ b/actiontext/lib/action_text/content.rb @@ -97,7 +97,9 @@ def append_attachables(attachables) def render_attachments(**options, &block) content = fragment.replace(ActionText::Attachment.tag_name) do |node| - node["content"] = sanitize_content_attachment(node["content"]) + if node.key? "content" + node["content"] = sanitize_content_attachment(node["content"]) + end block.call(attachment_for_node(node, **options)) end self.class.new(content, canonicalize: false) diff --git a/actiontext/test/unit/content_test.rb b/actiontext/test/unit/content_test.rb index a793364ad2..b04778c4bf 100644 --- a/actiontext/test/unit/content_test.rb +++ b/actiontext/test/unit/content_test.rb @@ -158,6 +158,18 @@ class ActionText::ContentTest < ActiveSupport::TestCase ActionText::ContentHelper.allowed_attributes = old_attrs end + test "sanitizes attachment markup for Trix" do + html = '' + trix_html = '
' + assert_equal trix_html, content_from_html(html).to_trix_html.strip + end + + test "does not add missing content attribute" do + html = '' + trix_html = '
' + assert_equal trix_html, content_from_html(html).to_trix_html.strip + end + test "renders with layout when in a new thread" do html = "

Hello world

" rendered = nil