diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb
index e82a2a33aa1..aba8ce9f615 100644
--- a/app/lib/sanitize_config.rb
+++ b/app/lib/sanitize_config.rb
@@ -25,6 +25,8 @@ class Sanitize
case env[:node_name]
when 'li'
env[:node].traverse do |node|
+ next unless %w(p ul ol li).include?(node.name)
+
node.add_next_sibling('
') if node.next_sibling
node.replace(node.children) unless node.text?
end
diff --git a/spec/lib/sanitize_config_spec.rb b/spec/lib/sanitize_config_spec.rb
index bb3cf6f0b23..54bd8693cc8 100644
--- a/spec/lib/sanitize_config_spec.rb
+++ b/spec/lib/sanitize_config_spec.rb
@@ -22,5 +22,9 @@ describe Sanitize::Config do
it 'converts ul inside ul' do
expect(Sanitize.fragment('
Foo
Bar
Baz
Check out:
', subject)).to eq 'Check out:
' + end end end