Skip to content

Commit

Permalink
Fix sanitizing lists contents (mastodon#11354)
Browse files Browse the repository at this point in the history
* Add test

* Fix code for sanitizing nested lists stripping all tags
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent a50d5db commit 10dec94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/lib/sanitize_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module Config
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('<br>') if node.next_sibling
node.replace(node.children) unless node.text?
end
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/sanitize_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
it 'converts ul inside ul' do
expect(Sanitize.fragment('<ul><li>Foo</li><li><ul><li>Bar</li><li>Baz</li></ul></li></ul>', subject)).to eq '<p>Foo<br>Bar<br>Baz</p>'
end

it 'keep links in lists' do
expect(Sanitize.fragment('<p>Check out:</p><ul><li><a href="https://joinmastodon.org" rel="nofollow noopener" target="_blank">joinmastodon.org</a></li><li>Bar</li></ul>', subject)).to eq '<p>Check out:</p><p><a href="https://joinmastodon.org" rel="nofollow noopener" target="_blank">joinmastodon.org</a><br>Bar</p>'
end
end
end

0 comments on commit 10dec94

Please sign in to comment.