From 103a9f4466986ef57fc4f3f15dea95866bdead3f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 16 Jun 2019 21:46:36 +0200 Subject: Fix sanitizer making block level elements unreadable (#10836) Fix #10834 --- app/lib/sanitize_config.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app') diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index 1bba4a5a6..e82a2a33a 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -19,6 +19,20 @@ class Sanitize node['class'] = class_list.join(' ') end + UNSUPPORTED_ELEMENTS_TRANSFORMER = lambda do |env| + return unless %w(h1 h2 h3 h4 h5 h6 blockquote pre ul ol li).include?(env[:node_name]) + + case env[:node_name] + when 'li' + env[:node].traverse do |node| + node.add_next_sibling('
') if node.next_sibling + node.replace(node.children) unless node.text? + end + else + env[:node].name = 'p' + end + end + MASTODON_STRICT ||= freeze_config( elements: %w(p br span a), @@ -40,6 +54,7 @@ class Sanitize transformers: [ CLASS_WHITELIST_TRANSFORMER, + UNSUPPORTED_ELEMENTS_TRANSFORMER, ] ) -- cgit