Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add action text initializer (#12402)

Łukasz Adamczykc75c8f63dfe7
diff --git a/admin/config/initializers/action_text.rb b/admin/config/initializers/action_text.rb
new file mode 100644
index 0000000000..c664c52bb0
--- /dev/null
+++ b/admin/config/initializers/action_text.rb
@@ -0,0 +1,8 @@
+# Since Rails 7.1 we can't use ActionText::ContentHelper.allowed_tags << ... to add more allowed tags
+# We need to configure the whole set ourselves, see: https://stackoverflow.com/a/77369507
+# Default allowed tags and attributes are copied from the rails action text helper: https://github.com/rails/rails/blob/main/actiontext/app/helpers/action_text/content_helper.rb#L68
+
+sanitizer_class = Rails::HTML4::Sanitizer.safe_list_sanitizer
+
+ActionText::ContentHelper.allowed_tags = sanitizer_class.allowed_tags + [ActionText::Attachment.tag_name, 'figure', 'figcaption', 'iframe']
+ActionText::ContentHelper.allowed_attributes = sanitizer_class.allowed_attributes + ActionText::Attachment::ATTRIBUTES + ['style']