From 773130d51a0295ed43799cc3e5473c49a5c5b091 Mon Sep 17 00:00:00 2001 From: ThibG Date: Fri, 19 Jul 2019 01:44:58 +0200 Subject: [PATCH] Fix sanitizing lists contents (#11354) * Add test * Fix code for sanitizing nested lists stripping all tags --- app/lib/sanitize_config.rb | 2 ++ spec/lib/sanitize_config_spec.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index e82a2a33aa..aba8ce9f61 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 bb3cf6f0b2..54bd8693cc 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('', subject)).to eq '

Foo
Bar
Baz

' end + + it 'keep links in lists' do + expect(Sanitize.fragment('

Check out:

', subject)).to eq '

Check out:

joinmastodon.org
Bar

' + end end end