From 6c4a196b53bb7d8b8ea8446d5e9c75ea72caab45 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 e82a2a33a..aba8ce9f6 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 bb3cf6f0b..54bd8693c 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