File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change
1
+ * Only sanitize ` content ` attribute when present in attachments.
2
+
3
+ * Petrik de Heus*
1
4
2
5
Please check [ 7-2-stable] ( https://github.com/rails/rails/blob/7-2-stable/actiontext/CHANGELOG.md ) for previous changes.
Original file line number Diff line number Diff line change @@ -97,7 +97,9 @@ def append_attachables(attachables)
97
97
98
98
def render_attachments ( **options , &block )
99
99
content = fragment . replace ( ActionText ::Attachment . tag_name ) do |node |
100
- node [ "content" ] = sanitize_content_attachment ( node [ "content" ] )
100
+ if node . key? "content"
101
+ node [ "content" ] = sanitize_content_attachment ( node [ "content" ] )
102
+ end
101
103
block . call ( attachment_for_node ( node , **options ) )
102
104
end
103
105
self . class . new ( content , canonicalize : false )
Original file line number Diff line number Diff line change @@ -158,6 +158,18 @@ class ActionText::ContentTest < ActiveSupport::TestCase
158
158
ActionText ::ContentHelper . allowed_attributes = old_attrs
159
159
end
160
160
161
+ test "sanitizes attachment markup for Trix" do
162
+ html = '<action-text-attachment content="<img src=\".\" onerror=alert>"></action-text-attachment>'
163
+ trix_html = '<figure data-trix-attachment="{"content":"<img src=\\"\\\\%22.\\\\%22\\">"}"></figure>'
164
+ assert_equal trix_html , content_from_html ( html ) . to_trix_html . strip
165
+ end
166
+
167
+ test "does not add missing content attribute" do
168
+ html = '<action-text-attachment sgid="123"></action-text-attachment>'
169
+ trix_html = '<figure data-trix-attachment="{"sgid":"123"}"></figure>'
170
+ assert_equal trix_html , content_from_html ( html ) . to_trix_html . strip
171
+ end
172
+
161
173
test "renders with layout when in a new thread" do
162
174
html = "<h1>Hello world</h1>"
163
175
rendered = nil
You can’t perform that action at this time.
0 commit comments