about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-06-16 21:46:36 +0200
committerGitHub <noreply@github.com>2019-06-16 21:46:36 +0200
commit103a9f4466986ef57fc4f3f15dea95866bdead3f (patch)
treed1eb4f964ccb0c8b36880f99db8ed95fdf5d0cbf /app/lib
parent65efe892cf56cd4f998de885bccc36e9231d8144 (diff)
Fix sanitizer making block level elements unreadable (#10836)
Fix #10834
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/sanitize_config.rb15
1 files changed, 15 insertions, 0 deletions
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('<br>') 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,
       ]
     )