File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change
1
+ * Strip ` content ` attribute if the key is present but the value is empty
2
+
3
+ * Jeremy Green*
4
+
1
5
* Rename ` rich_text_area ` methods into ` rich_textarea `
2
6
3
7
Old names are still available as aliases.
4
8
5
9
* Sean Doyle*
6
10
7
-
8
11
* Only sanitize ` content ` attribute when present in attachments.
9
12
10
13
* Petrik de Heus*
Original file line number Diff line number Diff line change @@ -97,8 +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
- if node . key? "content"
101
- node [ "content" ] = sanitize_content_attachment ( node [ "content" ] )
100
+ if node . key? ( "content" )
101
+ sanitized_content = sanitize_content_attachment ( node . remove_attribute ( "content" ) . to_s )
102
+ node [ "content" ] = sanitized_content if sanitized_content . present?
102
103
end
103
104
block . call ( attachment_for_node ( node , **options ) )
104
105
end
Original file line number Diff line number Diff line change @@ -164,6 +164,18 @@ class ActionText::ContentTest < ActiveSupport::TestCase
164
164
assert_equal trix_html , content_from_html ( html ) . to_trix_html . strip
165
165
end
166
166
167
+ test "removes content attribute if it's value is empty" do
168
+ html = '<action-text-attachment sgid="123" content=""></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
+
173
+ test "removes content attribute if it's value is empty after sanitization" do
174
+ html = '<action-text-attachment sgid="123" content="<script></script>"></action-text-attachment>'
175
+ trix_html = '<figure data-trix-attachment="{"sgid":"123"}"></figure>'
176
+ assert_equal trix_html , content_from_html ( html ) . to_trix_html . strip
177
+ end
178
+
167
179
test "does not add missing content attribute" do
168
180
html = '<action-text-attachment sgid="123"></action-text-attachment>'
169
181
trix_html = '<figure data-trix-attachment="{"sgid":"123"}"></figure>'
You can’t perform that action at this time.
0 commit comments